@syncfusion/ej2-image-editor 20.4.51 → 21.1.36

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.
Files changed (112) hide show
  1. package/.eslintrc.json +1 -0
  2. package/CHANGELOG.md +55 -5
  3. package/dist/ej2-image-editor.umd.min.js +2 -2
  4. package/dist/ej2-image-editor.umd.min.js.map +1 -1
  5. package/dist/es6/ej2-image-editor.es2015.js +20032 -11350
  6. package/dist/es6/ej2-image-editor.es2015.js.map +1 -1
  7. package/dist/es6/ej2-image-editor.es5.js +20027 -11313
  8. package/dist/es6/ej2-image-editor.es5.js.map +1 -1
  9. package/dist/global/ej2-image-editor.min.js +2 -2
  10. package/dist/global/ej2-image-editor.min.js.map +1 -1
  11. package/dist/global/index.d.ts +1 -1
  12. package/package.json +12 -12
  13. package/src/image-editor/action/crop.d.ts +36 -0
  14. package/src/image-editor/action/crop.js +829 -0
  15. package/src/image-editor/action/draw.d.ts +125 -0
  16. package/src/image-editor/action/draw.js +3263 -0
  17. package/src/image-editor/action/export.d.ts +23 -0
  18. package/src/image-editor/action/export.js +364 -0
  19. package/src/image-editor/action/filter.d.ts +35 -0
  20. package/src/image-editor/action/filter.js +699 -0
  21. package/src/image-editor/action/freehand-draw.d.ts +61 -0
  22. package/src/image-editor/action/freehand-draw.js +1015 -0
  23. package/src/image-editor/action/index.d.ts +9 -0
  24. package/src/image-editor/action/index.js +9 -0
  25. package/src/image-editor/action/selection.d.ts +139 -0
  26. package/src/image-editor/action/selection.js +4518 -0
  27. package/src/image-editor/action/shape.d.ts +94 -0
  28. package/src/image-editor/action/shape.js +2745 -0
  29. package/src/image-editor/action/transform.d.ts +67 -0
  30. package/src/image-editor/action/transform.js +1859 -0
  31. package/src/image-editor/action/undo-redo.d.ts +43 -0
  32. package/src/image-editor/action/undo-redo.js +800 -0
  33. package/src/image-editor/base/enum.d.ts +189 -0
  34. package/src/image-editor/base/enum.js +198 -0
  35. package/src/image-editor/base/image-editor-model.d.ts +626 -0
  36. package/src/image-editor/base/image-editor.d.ts +1300 -0
  37. package/src/image-editor/base/image-editor.js +2270 -0
  38. package/src/image-editor/base/index.d.ts +4 -0
  39. package/src/image-editor/base/index.js +2 -0
  40. package/src/image-editor/base/interface.d.ts +1128 -0
  41. package/src/image-editor/base/interface.js +1 -0
  42. package/src/image-editor/index.d.ts +3 -5
  43. package/src/image-editor/index.js +3 -4
  44. package/src/image-editor/renderer/index.d.ts +1 -0
  45. package/src/image-editor/renderer/index.js +1 -0
  46. package/src/image-editor/renderer/toolbar.d.ts +105 -0
  47. package/src/image-editor/renderer/toolbar.js +3018 -0
  48. package/styles/bootstrap-dark.css +79 -8
  49. package/styles/bootstrap.css +79 -8
  50. package/styles/bootstrap4.css +79 -8
  51. package/styles/bootstrap5-dark.css +81 -11
  52. package/styles/bootstrap5.css +81 -11
  53. package/styles/fabric-dark.css +79 -8
  54. package/styles/fabric.css +79 -8
  55. package/styles/fluent-dark.css +79 -8
  56. package/styles/fluent.css +79 -8
  57. package/styles/highcontrast-light.css +81 -10
  58. package/styles/highcontrast.css +82 -10
  59. package/styles/image-editor/_highcontrast-definition.scss +1 -1
  60. package/styles/image-editor/_highcontrast-light-definition.scss +1 -1
  61. package/styles/image-editor/_layout.scss +28 -18
  62. package/styles/image-editor/_material3-dark-definition.scss +1 -0
  63. package/styles/image-editor/_material3-definition.scss +10 -10
  64. package/styles/image-editor/_theme.scss +11 -6
  65. package/styles/image-editor/bootstrap-dark.css +79 -8
  66. package/styles/image-editor/bootstrap.css +79 -8
  67. package/styles/image-editor/bootstrap4.css +79 -8
  68. package/styles/image-editor/bootstrap5-dark.css +81 -11
  69. package/styles/image-editor/bootstrap5.css +81 -11
  70. package/styles/image-editor/fabric-dark.css +79 -8
  71. package/styles/image-editor/fabric.css +79 -8
  72. package/styles/image-editor/fluent-dark.css +79 -8
  73. package/styles/image-editor/fluent.css +79 -8
  74. package/styles/image-editor/highcontrast-light.css +81 -10
  75. package/styles/image-editor/highcontrast.css +82 -10
  76. package/styles/image-editor/icons/_bootstrap-dark.scss +132 -0
  77. package/styles/image-editor/icons/_bootstrap.scss +132 -0
  78. package/styles/image-editor/icons/_bootstrap4.scss +132 -0
  79. package/styles/image-editor/icons/_bootstrap5.scss +132 -0
  80. package/styles/image-editor/icons/_fabric-dark.scss +132 -0
  81. package/styles/image-editor/icons/_fabric.scss +132 -0
  82. package/styles/image-editor/icons/_fluent.scss +132 -0
  83. package/styles/image-editor/icons/_fusionnew.scss +132 -0
  84. package/styles/image-editor/icons/_highcontrast-light.scss +132 -0
  85. package/styles/image-editor/icons/_highcontrast.scss +132 -0
  86. package/styles/image-editor/icons/_material-dark.scss +132 -0
  87. package/styles/image-editor/icons/_material.scss +132 -0
  88. package/styles/image-editor/icons/_material3-dark.scss +1 -0
  89. package/styles/image-editor/icons/_material3.scss +133 -1
  90. package/styles/image-editor/icons/_tailwind.scss +132 -0
  91. package/styles/image-editor/material-dark.css +79 -16
  92. package/styles/image-editor/material.css +79 -11
  93. package/styles/image-editor/material3-dark.css +453 -0
  94. package/styles/image-editor/material3-dark.scss +14 -0
  95. package/styles/image-editor/material3.css +509 -0
  96. package/styles/image-editor/material3.scss +14 -0
  97. package/styles/image-editor/tailwind-dark.css +79 -8
  98. package/styles/image-editor/tailwind.css +79 -8
  99. package/styles/material-dark.css +79 -16
  100. package/styles/material.css +79 -11
  101. package/styles/material3-dark.css +453 -0
  102. package/styles/material3-dark.scss +3 -0
  103. package/styles/material3.css +509 -0
  104. package/styles/material3.scss +3 -0
  105. package/styles/tailwind-dark.css +79 -8
  106. package/styles/tailwind.css +79 -8
  107. package/GitLeaksReport.json +0 -1
  108. package/gitleaks-ci/gitleaks +0 -0
  109. package/gitleaks-ci.tar.gz +0 -0
  110. package/src/image-editor/image-editor-model.d.ts +0 -331
  111. package/src/image-editor/image-editor.d.ts +0 -1428
  112. package/src/image-editor/image-editor.js +0 -12849
@@ -0,0 +1,2745 @@
1
+ import { EventHandler, extend, isBlazor, isNullOrUndefined } from '@syncfusion/ej2-base';
2
+ import { ShapeType } from '../index';
3
+ var Shape = /** @class */ (function () {
4
+ function Shape(parent) {
5
+ this.textSettings = { text: 'Enter Text', fontFamily: 'Arial', fontSize: null, fontRatio: null, bold: false, italic: false, underline: false };
6
+ this.strokeSettings = { strokeColor: '#fff', fillColor: '', strokeWidth: null };
7
+ this.keyHistory = ''; // text history
8
+ this.parent = parent;
9
+ this.addEventListener();
10
+ }
11
+ Shape.prototype.destroy = function () {
12
+ if (this.parent.isDestroyed) {
13
+ return;
14
+ }
15
+ this.removeEventListener();
16
+ };
17
+ Shape.prototype.addEventListener = function () {
18
+ this.parent.on('shape', this.shape, this);
19
+ this.parent.on('destroyed', this.destroy, this);
20
+ };
21
+ Shape.prototype.removeEventListener = function () {
22
+ this.parent.off('shape', this.shape);
23
+ this.parent.off('destroyed', this.destroy);
24
+ };
25
+ Shape.prototype.shape = function (args) {
26
+ this.initShapePvtProps();
27
+ switch (args.prop) {
28
+ case 'drawEllipse':
29
+ this.drawEllipse(args.value['x'], args.value['y'], args.value['radiusX'], args.value['radiusY'], args.value['strokeWidth'], args.value['strokeColor'], args.value['fillColor']);
30
+ break;
31
+ case 'drawLine':
32
+ this.drawLine(args.value['startX'], args.value['startY'], args.value['endX'], args.value['endY'], args.value['strokeWidth'], args.value['strokeColor']);
33
+ break;
34
+ case 'drawArrow':
35
+ this.drawArrow(args.value['startX'], args.value['startY'], args.value['endX'], args.value['endY'], args.value['strokeWidth'], args.value['strokeColor'], args.value['arrowStart'], args.value['arrowEnd']);
36
+ break;
37
+ case 'drawPath':
38
+ this.drawPath(args.value['pointColl'], args.value['strokeWidth'], args.value['strokeColor']);
39
+ break;
40
+ case 'drawRectangle':
41
+ this.drawRectangle(args.value['x'], args.value['y'], args.value['width'], args.value['height'], args.value['strokeWidt'], args.value['strokeColor'], args.value['fillColor']);
42
+ break;
43
+ case 'drawText':
44
+ this.drawText(args.value['x'], args.value['y'], args.value['text'], args.value['fontFamily'], args.value['fontSize'], args.value['bold'], args.value['italic'], args.value['color']);
45
+ break;
46
+ case 'redrawActObj':
47
+ this.redrawActObj(args.value['x'], args.value['y'], args.value['isMouseDown']);
48
+ break;
49
+ case 'apply':
50
+ this.apply(args.value['shape'], args.value['obj'], args.value['canvas']);
51
+ break;
52
+ case 'updateShapeChangeEventArgs':
53
+ this.updateShapeChangeEventArgs(args.value['shapeSettings']);
54
+ break;
55
+ case 'updSelChangeEventArgs':
56
+ this.updSelChangeEventArgs(args.value['selectionSettings']);
57
+ break;
58
+ case 'iterateObjColl':
59
+ this.iterateObjColl();
60
+ break;
61
+ case 'updImgRatioForActObj':
62
+ this.updImgRatioForActObj();
63
+ break;
64
+ case 'zoomObjColl':
65
+ this.zoomObjColl(args.value['isPreventApply']);
66
+ break;
67
+ case 'redrawObj':
68
+ this.redrawObj(args.value['degree']);
69
+ break;
70
+ case 'rotateObjColl':
71
+ this.rotateObjColl();
72
+ break;
73
+ case 'draw-shape-text':
74
+ this.drawShapeText();
75
+ break;
76
+ case 'redraw-text':
77
+ this.redrawText();
78
+ break;
79
+ case 'draw-shape':
80
+ this.drawShape(args.value['obj'], args.value['strokeWidth'], args.value['strokeColor'], args.value['fillColor'], args.value['start'], args.value['width'], args.value['height']);
81
+ break;
82
+ case 'renderTextArea':
83
+ this.renderTextArea(args.value['x'], args.value['y'], args.value['actObj']);
84
+ break;
85
+ case 'setTextBoxWidth':
86
+ this.setTextBoxWidth(args.value['e']);
87
+ break;
88
+ case 'findTextTarget':
89
+ this.findTextTarget(args.value['e']);
90
+ break;
91
+ case 'panObjColl':
92
+ this.panObjColl(args.value['xDiff'], args.value['yDiff'], args.value['panRegion']);
93
+ break;
94
+ case 'updateFontStyles':
95
+ this.updateFontStyles(args.value['isTextBox']);
96
+ break;
97
+ case 'applyFontStyle':
98
+ this.applyFontStyle(args.value['item']);
99
+ break;
100
+ case 'updateFontRatio':
101
+ this.updateFontRatio(args.value['obj'], args.value['isTextArea']);
102
+ break;
103
+ case 'updateFontSize':
104
+ this.updateFontSize(args.value['obj']);
105
+ break;
106
+ case 'updateObjColl':
107
+ this.updateObjColl(args.value['item'], args.value['objColl']);
108
+ break;
109
+ case 'pushActItemIntoObj':
110
+ this.pushActItemIntoObj();
111
+ break;
112
+ case 'clearActObj':
113
+ this.clearActObj();
114
+ break;
115
+ case 'refreshActiveObj':
116
+ this.refreshActiveObj();
117
+ break;
118
+ case 'applyActObj':
119
+ this.applyActObj(args.value['isMouseDown']);
120
+ break;
121
+ case 'wireEvent':
122
+ EventHandler.add(this.parent.upperCanvas, 'dblclick', this.findTextTarget, this);
123
+ EventHandler.add(this.parent.textArea, 'mousedown', this.findTextTarget, this);
124
+ break;
125
+ case 'unWireEvent':
126
+ EventHandler.remove(this.parent.upperCanvas, 'dblclick', this.findTextTarget);
127
+ EventHandler.remove(this.parent.textArea, 'mousedown', this.findTextTarget);
128
+ break;
129
+ case 'getShapeSetting':
130
+ this.getShapeSetting(args.value['id'], args.value['obj']);
131
+ break;
132
+ case 'getShapeSettings':
133
+ this.getShapeSettings(args.value['obj']);
134
+ break;
135
+ case 'isPointsInRange':
136
+ this.isPointsInRange(args.value['x'], args.value['y'], args.value['obj']);
137
+ break;
138
+ case 'alignRotateFlipColl':
139
+ this.alignRotateFlipColl(args.value['collection'], args.value['isRotateFlipCollection'], args.value['obj']);
140
+ break;
141
+ case 'selectShape':
142
+ this.selectShape(args.value['id'], args.value['obj']);
143
+ break;
144
+ case 'deleteShape':
145
+ this.deleteShape(args.value['id']);
146
+ break;
147
+ case 'getMaxText':
148
+ this.getMaxText(args.value['isTextBox'], args.value['text'], args.value['obj']);
149
+ break;
150
+ case 'setPointCollForLineArrow':
151
+ args.value['obj'].pointColl = this.getLinePoints(args.value['obj'].activePoint.startX, args.value['obj'].activePoint.startY, args.value['obj'].activePoint.endX, args.value['obj'].activePoint.endY);
152
+ break;
153
+ case 'setPointCollForShapeRotation':
154
+ this.setPointCollForShapeRotation(args.value['obj']);
155
+ break;
156
+ case 'setTextSettings':
157
+ if (args.value['textSettings']) {
158
+ this.textSettings = args.value['textSettings'];
159
+ }
160
+ else if (args.value['fontFamily']) {
161
+ this.textSettings.fontFamily = args.value['fontFamily'];
162
+ }
163
+ else if (args.value['fontSize']) {
164
+ this.textSettings.fontSize = args.value['fontSize'];
165
+ }
166
+ break;
167
+ case 'setStrokeSettings':
168
+ if (args.value['strokeSettings']) {
169
+ this.strokeSettings = args.value['strokeSettings'];
170
+ }
171
+ else if (args.value['strokeColor']) {
172
+ this.strokeSettings.strokeColor = args.value['strokeColor'];
173
+ }
174
+ else if (args.value['fillColor']) {
175
+ this.strokeSettings.fillColor = args.value['fillColor'];
176
+ }
177
+ else if (args.value['strokeWidth']) {
178
+ this.strokeSettings.strokeWidth = args.value['strokeWidth'];
179
+ }
180
+ break;
181
+ case 'getStrokeSettings':
182
+ args.value['obj']['strokeSettings'] = this.strokeSettings;
183
+ break;
184
+ case 'setKeyHistory':
185
+ this.keyHistory = args.value['keyHistory'];
186
+ break;
187
+ case 'getKeyHistory':
188
+ args.value['obj']['keyHistory'] = this.keyHistory;
189
+ break;
190
+ case 'setTextBoxPos':
191
+ this.setTextBoxPos(args.value['actObj'], args.value['degree'], args.value['flip'], args.value['x'], args.value['y']);
192
+ break;
193
+ case 'setTextBoxPoints':
194
+ this.setTextBoxPoints(args.value['actObj'], args.value['degree'], args.value['flip'], args.value['x'], args.value['y']);
195
+ break;
196
+ case 'alignTextAreaIntoCanvas':
197
+ this.alignTextAreaIntoCanvas();
198
+ break;
199
+ case 'initializeTextShape':
200
+ this.initializeTextShape(args.value['text'], args.value['fontFamily'], args.value['fontSize'], args.value['bold'], args.value['italic'], args.value['strokeColor']);
201
+ break;
202
+ case 'stopPathDrawing':
203
+ this.stopPathDrawing(args.value['e']);
204
+ break;
205
+ case 'updateArrowRatio':
206
+ this.updateArrowRatio(args.value['obj']);
207
+ break;
208
+ case 'getSquarePointForRotatedShape':
209
+ this.getSquarePointForRotatedShape(args.value['obj'], args.value['object']);
210
+ break;
211
+ case 'reset':
212
+ this.reset();
213
+ break;
214
+ }
215
+ };
216
+ Shape.prototype.getModuleName = function () {
217
+ return 'shape';
218
+ };
219
+ Shape.prototype.initShapePvtProps = function () {
220
+ if (this.parent.lowerCanvas) {
221
+ this.lowerContext = this.parent.lowerCanvas.getContext('2d');
222
+ }
223
+ if (this.parent.upperCanvas) {
224
+ this.upperContext = this.parent.upperCanvas.getContext('2d');
225
+ }
226
+ };
227
+ Shape.prototype.reset = function () {
228
+ this.textSettings =
229
+ { text: 'Enter Text', fontFamily: 'Arial', fontSize: null, fontRatio: null, bold: false, italic: false, underline: false };
230
+ this.strokeSettings = { strokeColor: '#fff', fillColor: '', strokeWidth: null };
231
+ };
232
+ Shape.prototype.drawEllipse = function (x, y, radiusX, radiusY, strokeWidth, strokeColor, fillColor) {
233
+ this.initializeShape('ellipse');
234
+ var start = x && y ? { x: x, y: y } : null;
235
+ this.drawShape('ellipse', strokeWidth, strokeColor, fillColor, start, radiusX, radiusY);
236
+ };
237
+ Shape.prototype.drawLine = function (startX, startY, endX, endY, strokeWidth, strokeColor) {
238
+ this.initializeShape('line');
239
+ var start = startX && startY ? { x: startX, y: startY } : null;
240
+ var width = endX - startX;
241
+ var height = endY - startY;
242
+ this.drawShape('line', strokeWidth, strokeColor, null, start, width, height);
243
+ };
244
+ Shape.prototype.drawPath = function (pointColl, strokeWidth, strokeColor) {
245
+ this.initializeShape('path');
246
+ if (pointColl) {
247
+ this.drawShape('path', strokeWidth, strokeColor, null, null, null, null, pointColl);
248
+ }
249
+ else {
250
+ this.drawShape('line', strokeWidth, strokeColor, null, null, null, null);
251
+ var obj = extend({}, this.parent.objColl[this.parent.objColl.length - 1], null, true);
252
+ obj.shape = 'path';
253
+ obj.lineDraw = null;
254
+ obj.pointColl = [{ x: obj.activePoint.startX, y: obj.activePoint.startY },
255
+ { x: obj.activePoint.endX, y: obj.activePoint.endY }];
256
+ this.parent.objColl[this.parent.objColl.length - 1] = obj;
257
+ }
258
+ };
259
+ Shape.prototype.drawArrow = function (startX, startY, endX, endY, strokeWidth, strokeColor, arrowStart, arrowEnd) {
260
+ this.initializeShape('arrow');
261
+ var start = startX && startY ? { x: startX, y: startY } : null;
262
+ var width = endX - startX;
263
+ var height = endY - startY;
264
+ this.drawShape('arrow', strokeWidth, strokeColor, null, start, width, height, null, arrowStart, arrowEnd);
265
+ };
266
+ Shape.prototype.drawRectangle = function (x, y, width, height, strokeWidth, strokeColor, fillColor) {
267
+ this.initializeShape('rectangle');
268
+ var start = x && y ? { x: x, y: y } : null;
269
+ this.drawShape('rectangle', strokeWidth, strokeColor, fillColor, start, width, height);
270
+ };
271
+ Shape.prototype.drawText = function (x, y, text, fontFamily, fontSize, bold, italic, color) {
272
+ this.drawShapeText(text, fontFamily, fontSize, bold, italic, color, x, y);
273
+ };
274
+ Shape.prototype.initializeShape = function (type) {
275
+ this.redrawActObj();
276
+ this.parent.activeObj.shape = type;
277
+ if (this.parent.currObjType.shape === 'freehanddraw') {
278
+ this.apply();
279
+ this.parent.upperCanvas.style.cursor = this.parent.cursor = 'default';
280
+ this.parent.currObjType.shape = '';
281
+ }
282
+ this.parent.currObjType.isCustomCrop = false;
283
+ };
284
+ Shape.prototype.updateWidthHeight = function (obj) {
285
+ obj.activePoint.width = obj.activePoint.endX - obj.activePoint.startX;
286
+ obj.activePoint.height = obj.activePoint.endY - obj.activePoint.startY;
287
+ return obj;
288
+ };
289
+ Shape.prototype.setDimension = function (width, height) {
290
+ if (width && height) {
291
+ this.parent.activeObj.activePoint.width = width;
292
+ this.parent.activeObj.activePoint.height = height;
293
+ if (this.parent.currObjType.shape.toLowerCase() === 'ellipse') {
294
+ this.parent.activeObj.activePoint.width = 2 * width;
295
+ this.parent.activeObj.activePoint.height = 2 * height;
296
+ }
297
+ }
298
+ };
299
+ Shape.prototype.getArrowType = function (type) {
300
+ var arrowType = type;
301
+ if (type) {
302
+ var typeToArrowType = { 'None': 'none', 'Arrow': 'arrow', 'SolidArrow': 'arrowSolid',
303
+ 'Circle': 'circle', 'SolidCircle': 'circleSolid', 'Square': 'square', 'SolidSquare': 'squareSolid', 'Bar': 'bar' };
304
+ arrowType = typeToArrowType["" + type];
305
+ }
306
+ return arrowType;
307
+ };
308
+ Shape.prototype.drawShape = function (type, strokeWidth, strokeColor, fillColor, start, width, height, pointColl, arrowStart, arrowEnd) {
309
+ var _this = this;
310
+ var parent = this.parent;
311
+ if (!parent.disabled && parent.isImageLoaded) {
312
+ parent.notify('draw', { prop: 'setImageEdited', onPropertyChange: false });
313
+ this.redrawActObj();
314
+ var objColl_1 = extend([], parent.objColl, [], true);
315
+ parent.togglePen = false;
316
+ this.keyHistory = '';
317
+ this.parent.upperCanvas.style.display = 'block';
318
+ this.refreshActiveObj();
319
+ parent.currObjType.shape = type;
320
+ if (parent.currObjType.shape.toLowerCase() === 'path' && isNullOrUndefined(pointColl)) {
321
+ parent.activeObj.shape = parent.currObjType.shape.toLowerCase();
322
+ parent.activeObj.pointColl = [];
323
+ parent.upperCanvas.style.cursor = this.parent.cursor = 'crosshair';
324
+ parent.notify('selection', { prop: 'setCurrentDrawingShape', onPropertyChange: false, value: { value: 'path' } });
325
+ if (!isBlazor()) {
326
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: { type: 'shapes',
327
+ isApplyBtn: null, isCropping: null, isZooming: null, cType: null } });
328
+ parent.notify('toolbar', { prop: 'update-toolbar-items', onPropertyChange: false });
329
+ }
330
+ }
331
+ else {
332
+ if (parent.currObjType.shape.toLowerCase() !== 'freehanddraw' && parent.currObjType.shape.toLowerCase() !== '') {
333
+ parent.activeObj.shape = parent.currObjType.shape.toLowerCase();
334
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
335
+ if (isNullOrUndefined(parent.activeObj.strokeSettings)) {
336
+ parent.activeObj.strokeSettings = this.strokeSettings;
337
+ }
338
+ if (parent.currObjType.shape.toLowerCase() === 'path' && pointColl) {
339
+ parent.activeObj.pointColl = pointColl;
340
+ }
341
+ parent.activeObj.strokeSettings.strokeWidth = strokeWidth ? strokeWidth : parent.activeObj.strokeSettings.strokeWidth;
342
+ parent.activeObj.strokeSettings.strokeColor = strokeColor ? strokeColor : parent.activeObj.strokeSettings.strokeColor;
343
+ parent.activeObj.strokeSettings.fillColor = fillColor ? fillColor : parent.activeObj.strokeSettings.fillColor;
344
+ var tempWidth = parent.img.destWidth > 100 ? 100 : parent.img.destWidth / 2;
345
+ var tempHeight = parent.img.destHeight > 100 ? 100 : parent.img.destHeight / 2;
346
+ parent.activeObj.activePoint.width = tempWidth;
347
+ parent.activeObj.activePoint.height = tempHeight;
348
+ if (parent.currObjType.shape.toLowerCase() === 'line' || parent.currObjType.shape.toLowerCase() === 'arrow') {
349
+ parent.activeObj.lineDraw = 'horizontal';
350
+ parent.activeObj.activePoint.height = 0;
351
+ if (parent.currObjType.shape.toLowerCase() === 'arrow') {
352
+ parent.activeObj.activePoint.width += 50;
353
+ parent.activeObj.start = this.getArrowType(arrowStart);
354
+ parent.activeObj.end = this.getArrowType(arrowEnd);
355
+ }
356
+ }
357
+ else if (parent.currObjType.shape.toLowerCase() === 'rectangle') {
358
+ parent.activeObj.activePoint.width += parent.activeObj.activePoint.width / 2;
359
+ }
360
+ this.setDimension(width, height);
361
+ if (start) {
362
+ parent.activeObj.activePoint.startX = start.x;
363
+ parent.activeObj.activePoint.startY = start.y;
364
+ parent.activeObj.activePoint.endX = parent.activeObj.activePoint.startX +
365
+ parent.activeObj.activePoint.width;
366
+ parent.activeObj.activePoint.endY = parent.activeObj.activePoint.startY +
367
+ parent.activeObj.activePoint.height;
368
+ }
369
+ else {
370
+ this.setCenterPoints();
371
+ }
372
+ this.setPointCollForLineAndArrow();
373
+ if (parent.currObjType.shape.toLowerCase() === 'arrow') {
374
+ parent.activeObj.triangleDirection = 'right';
375
+ }
376
+ parent.currObjType.isDragging = parent.currObjType.isCustomCrop = false;
377
+ parent.activeObj.shapeDegree = parent.transform.degree;
378
+ parent.activeObj.shapeFlip = parent.transform.currFlipState;
379
+ parent.activeObj.textFlip = parent.transform.currFlipState;
380
+ parent.activeObj.flipObjColl = [];
381
+ var obj = { shapeSettingsObj: {} };
382
+ parent.notify('selection', { prop: 'updatePrevShapeSettings', onPropertyChange: false, value: { obj: obj } });
383
+ var shapeSettings = obj['shapeSettingsObj'];
384
+ var shapeChangingArgs = { action: 'insert', previousShapeSettings: shapeSettings,
385
+ currentShapeSettings: shapeSettings };
386
+ if (isBlazor() && parent.events && parent.events.shapeChanging.hasDelegate === true) {
387
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
388
+ this.parent.dotNetRef.invokeMethodAsync('ShapeEventAsync', 'OnShape', shapeChangingArgs).then(function (shapeChangingArgs) {
389
+ _this.updateShapeChangeEventArgs(shapeChangingArgs.currentShapeSettings);
390
+ _this.setDimension(width, height);
391
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'duplicate' } });
392
+ parent.updateToolbar(parent.element, 'quickAccessToolbar', 'shape');
393
+ parent.notify('selection', { prop: 'isShapeInserted', onPropertyChange: false, value: { bool: true } });
394
+ parent.notify('undo-redo', { prop: 'updateUrObj', onPropertyChange: false, value: { objColl: objColl_1 } });
395
+ if (parent.isPublicMethod) {
396
+ parent.notify('undo-redo', { prop: 'updateUndoRedo', onPropertyChange: false });
397
+ }
398
+ parent.isPublicMethod = false;
399
+ });
400
+ }
401
+ else {
402
+ parent.trigger('shapeChanging', shapeChangingArgs);
403
+ this.updateShapeChangeEventArgs(shapeChangingArgs.currentShapeSettings);
404
+ this.setDimension(width, height);
405
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'duplicate' } });
406
+ if (!isBlazor()) {
407
+ parent.notify('toolbar', { prop: 'renderQAT', onPropertyChange: false, value: { isPenEdit: null } });
408
+ }
409
+ else {
410
+ parent.updateToolbar(parent.element, 'quickAccessToolbar', 'shape');
411
+ }
412
+ parent.notify('selection', { prop: 'isShapeInserted', onPropertyChange: false, value: { bool: true } });
413
+ parent.notify('undo-redo', { prop: 'updateUrObj', onPropertyChange: false, value: { objColl: objColl_1 } });
414
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: { type: 'shapes',
415
+ isApplyBtn: null, isCropping: null, isZooming: null, cType: null } });
416
+ parent.notify('toolbar', { prop: 'update-toolbar-items', onPropertyChange: false });
417
+ if (parent.isPublicMethod) {
418
+ parent.notify('undo-redo', { prop: 'updateUndoRedo', onPropertyChange: false });
419
+ }
420
+ parent.isPublicMethod = false;
421
+ }
422
+ }
423
+ }
424
+ }
425
+ };
426
+ Shape.prototype.setPointCollForLineAndArrow = function () {
427
+ var parent = this.parent;
428
+ if (parent.activeObj.shape === 'line' || parent.activeObj.shape === 'arrow') {
429
+ parent.activeObj.pointColl = this.getLinePoints(parent.activeObj.activePoint.startX, parent.activeObj.activePoint.startY, parent.activeObj.activePoint.endX, parent.activeObj.activePoint.endY);
430
+ if (parent.activeObj.pointColl) {
431
+ for (var i = 0, len = parent.activeObj.pointColl.length; i < len; i++) {
432
+ parent.activeObj.pointColl[i].ratioX = (parent.activeObj.pointColl[i].x -
433
+ parent.img.destLeft) / parent.img.destWidth;
434
+ parent.activeObj.pointColl[i].ratioY = (parent.activeObj.pointColl[i].y -
435
+ parent.img.destTop) / parent.img.destHeight;
436
+ }
437
+ }
438
+ }
439
+ };
440
+ Shape.prototype.drawShapeText = function (text, fontFamily, fontSize, bold, italic, strokeColor, x, y) {
441
+ var _this = this;
442
+ var parent = this.parent;
443
+ if (!parent.disabled && parent.isImageLoaded) {
444
+ if (parent.currObjType.shape === 'freehanddraw') {
445
+ this.apply();
446
+ parent.upperCanvas.style.cursor = parent.cursor = 'default';
447
+ parent.currObjType.shape = '';
448
+ }
449
+ parent.notify('draw', { prop: 'setImageEdited', onPropertyChange: false });
450
+ parent.togglePen = false;
451
+ this.redrawActObj();
452
+ var object = { currObj: {} };
453
+ parent.notify('filter', { prop: 'getCurrentObj', onPropertyChange: false, value: { object: object } });
454
+ this.prevObj = object['currObj'];
455
+ this.prevObj.objColl = extend([], parent.objColl, [], true);
456
+ this.prevObj.pointColl = extend([], parent.pointColl, [], true);
457
+ this.prevObj.afterCropActions = extend([], parent.afterCropActions, [], true);
458
+ var selPointCollObj = { selPointColl: null };
459
+ parent.notify('freehand-draw', { prop: 'getSelPointColl', onPropertyChange: false,
460
+ value: { obj: selPointCollObj } });
461
+ this.prevObj.selPointColl = extend([], selPointCollObj['selPointColl'], [], true);
462
+ this.refreshActiveObj();
463
+ parent.activeObj.shape = parent.currObjType.shape = 'text';
464
+ parent.currObjType.isCustomCrop = false;
465
+ this.initializeTextShape(text, fontFamily, fontSize, bold, italic, strokeColor);
466
+ parent.currObjType.isText = parent.currObjType.isInitialText = true;
467
+ if (isNullOrUndefined(parent.activeObj.textSettings.fontSize)) {
468
+ if (parent.img.destWidth > parent.img.destHeight) {
469
+ parent.activeObj.textSettings.fontSize = (parent.img.destWidth / 15);
470
+ }
471
+ else {
472
+ parent.activeObj.textSettings.fontSize = (parent.img.destHeight / 15);
473
+ }
474
+ if (parent.activeObj.textSettings.fontSize < 20) {
475
+ parent.activeObj.textSettings.fontSize = 20;
476
+ }
477
+ }
478
+ if (parent.img.destWidth < 100) {
479
+ parent.activeObj.textSettings.fontSize = Math.floor((parent.img.destWidth / 20));
480
+ }
481
+ else if (parent.img.destHeight < 100) {
482
+ parent.activeObj.textSettings.fontSize = Math.floor((parent.img.destHeight / 20));
483
+ }
484
+ parent.activeObj.shapeDegree = parent.transform.degree;
485
+ parent.activeObj.shapeFlip = parent.transform.currFlipState;
486
+ parent.activeObj.flipObjColl = [];
487
+ this.updateFontStyles();
488
+ var width = this.upperContext.measureText(parent.activeObj.textSettings.text).width +
489
+ parent.activeObj.textSettings.fontSize * 0.5;
490
+ var height = parent.activeObj.textSettings.fontSize + parent.activeObj.textSettings.fontSize * 0.25;
491
+ if (!isNullOrUndefined(x) && !isNullOrUndefined(y)) {
492
+ parent.activeObj.activePoint.startX = x;
493
+ parent.activeObj.activePoint.startY = y;
494
+ parent.activeObj.activePoint.endX = parent.activeObj.activePoint.startX + width;
495
+ parent.activeObj.activePoint.endY = parent.activeObj.activePoint.startY + height;
496
+ }
497
+ else {
498
+ this.setCenterPoints(true, width, height);
499
+ }
500
+ var obj = { shapeSettingsObj: {} };
501
+ parent.notify('selection', { prop: 'updatePrevShapeSettings', onPropertyChange: false, value: { obj: obj } });
502
+ var shapeSettings = obj['shapeSettingsObj'];
503
+ var shapeChangingArgs = { action: 'insert', previousShapeSettings: shapeSettings,
504
+ currentShapeSettings: shapeSettings };
505
+ if (isBlazor() && parent.events && parent.events.shapeChanging.hasDelegate === true) {
506
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
507
+ parent.dotNetRef.invokeMethodAsync('ShapeEventAsync', 'OnShape', shapeChangingArgs).then(function (shapeChangingArgs) {
508
+ _this.drawShapeTextEvent(shapeChangingArgs);
509
+ if (parent.isPublicMethod) {
510
+ parent.notify('undo-redo', { prop: 'updateUndoRedo', onPropertyChange: false });
511
+ }
512
+ parent.isPublicMethod = false;
513
+ });
514
+ }
515
+ else {
516
+ parent.trigger('shapeChanging', shapeChangingArgs);
517
+ this.drawShapeTextEvent(shapeChangingArgs);
518
+ if (parent.isPublicMethod) {
519
+ parent.notify('undo-redo', { prop: 'updateUndoRedo', onPropertyChange: false });
520
+ }
521
+ parent.isPublicMethod = false;
522
+ }
523
+ }
524
+ };
525
+ Shape.prototype.drawShapeTextEvent = function (shapeChangingArgs) {
526
+ var parent = this.parent;
527
+ this.updateShapeChangeEventArgs(shapeChangingArgs.currentShapeSettings);
528
+ this.addLetter(parent.activeObj.textSettings.text);
529
+ parent.activeObj.textFlip = parent.transform.currFlipState;
530
+ this.updateFontRatio(parent.activeObj);
531
+ parent.objColl.push(parent.activeObj);
532
+ var prevCropObj = extend({}, parent.cropObj, {}, true);
533
+ parent.notify('undo-redo', { prop: 'updateUndoRedoColl', onPropertyChange: false,
534
+ value: { operation: 'shapeTransform', previousObj: this.prevObj, previousObjColl: this.prevObj.objColl,
535
+ previousPointColl: this.prevObj.pointColl, previousSelPointColl: this.prevObj.selPointColl,
536
+ previousCropObj: prevCropObj, previousText: null,
537
+ currentText: null, previousFilter: null, isCircleCrop: null } });
538
+ parent.notify('selection', { prop: 'redrawShape', onPropertyChange: false,
539
+ value: { obj: parent.objColl[parent.objColl.length - 1] } });
540
+ if (!isBlazor()) {
541
+ parent.notify('toolbar', { prop: 'renderQAT', onPropertyChange: false, value: { isPenEdit: null } });
542
+ }
543
+ else {
544
+ parent.updateToolbar(parent.element, 'quickAccessToolbar', 'text');
545
+ }
546
+ parent.notify('selection', { prop: 'isShapeInserted', onPropertyChange: false, value: { bool: true } });
547
+ if (!isBlazor()) {
548
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: { type: 'text',
549
+ isApplyBtn: null, isCropping: null, isZooming: null, cType: null } });
550
+ parent.notify('toolbar', { prop: 'update-toolbar-items', onPropertyChange: false });
551
+ }
552
+ };
553
+ Shape.prototype.initializeTextShape = function (text, fontFamily, fontSize, bold, italic, strokeColor) {
554
+ var parent = this.parent;
555
+ this.keyHistory = '';
556
+ parent.upperCanvas.style.display = 'block';
557
+ if (isNullOrUndefined(parent.activeObj.textSettings)) {
558
+ parent.activeObj.textSettings = this.textSettings;
559
+ }
560
+ if (isNullOrUndefined(parent.activeObj.strokeSettings)) {
561
+ parent.activeObj.strokeSettings = this.strokeSettings;
562
+ }
563
+ parent.activeObj.strokeSettings.strokeColor = strokeColor || parent.activeObj.strokeSettings.strokeColor;
564
+ parent.activeObj.textSettings.text = text || parent.activeObj.textSettings.text;
565
+ parent.activeObj.textSettings.fontFamily = fontFamily || parent.activeObj.textSettings.fontFamily;
566
+ parent.activeObj.textSettings.fontSize = fontSize || parent.activeObj.textSettings.fontSize;
567
+ parent.activeObj.textSettings.bold = bold || parent.activeObj.textSettings.bold;
568
+ parent.activeObj.textSettings.italic = italic || parent.activeObj.textSettings.italic;
569
+ };
570
+ Shape.prototype.redrawActObj = function (x, y, isMouseDown) {
571
+ var splitWords;
572
+ var parent = this.parent;
573
+ if (parent.activeObj.shape) {
574
+ splitWords = parent.activeObj.shape.split('-');
575
+ }
576
+ if (parent.activeObj.horTopLine && (parent.activeObj.shape && splitWords[0] !== 'crop')) {
577
+ if (parent.textArea.style.display === 'block') {
578
+ parent.notify('selection', { prop: 'setTextBoxStylesToActObj', onPropertyChange: false });
579
+ this.updateFontRatio(parent.activeObj, true);
580
+ if (x && y) {
581
+ if ((x !== parent.activeObj.activePoint.startX) && (y !== parent.activeObj.activePoint.startY)) {
582
+ this.updateTextFromTextArea();
583
+ this.applyActObj();
584
+ }
585
+ }
586
+ else {
587
+ this.updateTextFromTextArea();
588
+ this.apply(parent.activeObj.shape, parent.activeObj);
589
+ parent.objColl.push(parent.activeObj);
590
+ this.refreshActiveObj();
591
+ parent.textArea.style.transform = '';
592
+ parent.notify('toolbar', { prop: 'refresh-main-toolbar', onPropertyChange: false });
593
+ }
594
+ }
595
+ else {
596
+ this.applyActObj(isMouseDown);
597
+ }
598
+ }
599
+ };
600
+ Shape.prototype.apply = function (shape, obj, canvas) {
601
+ var parent = this.parent;
602
+ if (!parent.disabled) {
603
+ if (parent.togglePen && !parent.currObjType.isCustomCrop) {
604
+ var destLeft = parent.img.destLeft;
605
+ var destTop = parent.img.destTop;
606
+ var destWidth = parent.img.destWidth;
607
+ var destHeight = parent.img.destHeight;
608
+ parent.notify('draw', { prop: 'callUpdateCurrTransState', onPropertyChange: false });
609
+ var temp = this.lowerContext.filter;
610
+ this.lowerContext.filter = 'none';
611
+ parent.togglePen = false;
612
+ this.iterateObjColl();
613
+ parent.notify('freehandDraw', { prop: 'freehandRedraw', onPropertyChange: false,
614
+ value: { context: this.lowerContext, points: null } });
615
+ parent.togglePen = false;
616
+ if (parent.isCircleCrop || (parent.currSelectionPoint &&
617
+ parent.currSelectionPoint.shape === 'crop-circle')) {
618
+ parent.notify('crop', { prop: 'cropCircle', onPropertyChange: false,
619
+ value: { context: this.lowerContext, isSave: null, isFlip: null } });
620
+ }
621
+ parent.img.destLeft = destLeft;
622
+ parent.img.destTop = destTop;
623
+ parent.img.destWidth = destWidth;
624
+ parent.img.destHeight = destHeight;
625
+ this.lowerContext.filter = temp;
626
+ }
627
+ else {
628
+ canvas = canvas ? canvas : 'original';
629
+ if (isNullOrUndefined(parent.activeObj.shape) && isNullOrUndefined(shape)) {
630
+ parent.currObjType.shape = '';
631
+ }
632
+ else {
633
+ parent.currObjType.shape = shape || parent.currObjType.shape;
634
+ }
635
+ if (parent.currObjType.shape !== '') {
636
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
637
+ if (parent.activeObj.shape === 'text') {
638
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: canvas, obj: obj, isCropRatio: null,
639
+ points: null, isPreventDrag: true, saveContext: null, isPreventSelection: null } });
640
+ parent.notify('draw', { prop: 'clearOuterCanvas', onPropertyChange: false, value: { context: this.lowerContext } });
641
+ }
642
+ else {
643
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: canvas, obj: obj } });
644
+ }
645
+ parent.activeObj.shape = parent.currObjType.shape.toLowerCase();
646
+ if (!shape && parent.currObjType.shape !== '' && !parent.currObjType.isCustomCrop) {
647
+ parent.objColl.push(extend({}, parent.activeObj, {}, true));
648
+ }
649
+ this.keyHistory = '';
650
+ }
651
+ }
652
+ }
653
+ };
654
+ Shape.prototype.setCenterPoints = function (text, width, height) {
655
+ var parent = this.parent;
656
+ var renderWidth;
657
+ var renderHeight;
658
+ if (text && width && height) {
659
+ renderWidth = width;
660
+ renderHeight = height;
661
+ }
662
+ else {
663
+ renderWidth = parent.activeObj.activePoint.width;
664
+ renderHeight = parent.activeObj.activePoint.height;
665
+ }
666
+ parent.activeObj.activePoint.startX = (parent.lowerCanvas.width / 2) - renderWidth / 2;
667
+ parent.activeObj.activePoint.startY = (parent.lowerCanvas.height / 2) - renderHeight / 2;
668
+ parent.activeObj.activePoint.endX = (parent.lowerCanvas.width / 2) + renderWidth / 2;
669
+ parent.activeObj.activePoint.endY = (parent.lowerCanvas.height / 2) + renderHeight / 2;
670
+ };
671
+ Shape.prototype.updSelChangeEventArgs = function (selectionSettings) {
672
+ var parent = this.parent;
673
+ parent.activeObj.activePoint.startX = selectionSettings.startX;
674
+ parent.activeObj.activePoint.startY = selectionSettings.startY;
675
+ parent.activeObj.activePoint.width = selectionSettings.width;
676
+ parent.activeObj.activePoint.height = selectionSettings.height;
677
+ parent.activeObj.activePoint.endX = parent.activeObj.activePoint.startX + parent.activeObj.activePoint.width;
678
+ parent.activeObj.activePoint.endY = parent.activeObj.activePoint.startY + parent.activeObj.activePoint.height;
679
+ };
680
+ Shape.prototype.updateShapeChangeEventArgs = function (shapeSettings) {
681
+ var parent = this.parent;
682
+ parent.activeObj.currIndex = shapeSettings.id;
683
+ parent.activeObj.activePoint.startX = shapeSettings.startX;
684
+ parent.activeObj.activePoint.startY = shapeSettings.startY;
685
+ parent.activeObj.activePoint.width = shapeSettings.width;
686
+ parent.activeObj.activePoint.height = shapeSettings.height;
687
+ parent.activeObj.activePoint.endX = parent.activeObj.activePoint.startX + parent.activeObj.activePoint.width;
688
+ parent.activeObj.activePoint.endY = parent.activeObj.activePoint.startY + parent.activeObj.activePoint.height;
689
+ parent.activeObj.strokeSettings.strokeColor = shapeSettings.strokeColor;
690
+ parent.activeObj.strokeSettings.fillColor = shapeSettings.fillColor;
691
+ switch (parent.activeObj.shape) {
692
+ case 'ellipse':
693
+ parent.activeObj.activePoint.width = shapeSettings.radius / 2;
694
+ break;
695
+ case 'line':
696
+ case 'arrow':
697
+ parent.activeObj.activePoint.width = shapeSettings.length;
698
+ break;
699
+ case 'text':
700
+ parent.activeObj.keyHistory = shapeSettings.text;
701
+ parent.activeObj.textSettings.fontSize = shapeSettings.fontSize;
702
+ parent.activeObj.strokeSettings.strokeColor = shapeSettings.color;
703
+ break;
704
+ }
705
+ if (parent.activeObj.shape === 'text' && parent.activeObj.textSettings) {
706
+ for (var i = 0; i < shapeSettings.fontStyle.length; i++) {
707
+ switch (shapeSettings.fontStyle[i]) {
708
+ case 'bold':
709
+ parent.activeObj.textSettings.bold = true;
710
+ break;
711
+ case 'italic':
712
+ parent.activeObj.textSettings.italic = true;
713
+ break;
714
+ case 'underline':
715
+ parent.activeObj.textSettings.underline = true;
716
+ break;
717
+ }
718
+ }
719
+ }
720
+ };
721
+ Shape.prototype.addLetter = function (letter) {
722
+ var parent = this.parent;
723
+ if (parent.textArea.style.display === 'none' && (parent.currObjType.isText || parent.activeObj.shape === 'text')) {
724
+ if (letter === 'Backspace') {
725
+ this.keyHistory = this.keyHistory.slice(0, -1);
726
+ }
727
+ else {
728
+ this.keyHistory += letter;
729
+ }
730
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
731
+ this.updateFontStyles();
732
+ var width = this.upperContext.measureText(this.keyHistory).width
733
+ + parent.activeObj.textSettings.fontSize * 0.5;
734
+ var height = parent.activeObj.textSettings.fontSize + parent.activeObj.textSettings.fontSize * 0.25;
735
+ this.upperContext.fillText(this.keyHistory, parent.activeObj.activePoint.startX, parent.activeObj.activePoint.startY +
736
+ parent.activeObj.textSettings.fontSize);
737
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
738
+ parent.currObjType.isText = true;
739
+ parent.notify('selection', { prop: 'setActivePoint', onPropertyChange: false,
740
+ value: { startX: width, startY: height } });
741
+ }
742
+ };
743
+ Shape.prototype.redrawText = function () {
744
+ var parent = this.parent;
745
+ var fontStyle = '';
746
+ if (parent.activeObj.textSettings.bold) {
747
+ fontStyle += 'bold ';
748
+ }
749
+ if (parent.activeObj.textSettings.italic) {
750
+ fontStyle += 'italic ';
751
+ }
752
+ this.upperContext.font = fontStyle + parent.activeObj.textSettings.fontSize + 'px ' + parent.activeObj.textSettings.fontFamily;
753
+ var rows = parent.activeObj.keyHistory.split('\n');
754
+ var text = parent.textArea.style.display === 'block' ? this.getMaxText(true) : this.getMaxText();
755
+ var width = this.upperContext.measureText(text).width + parent.activeObj.textSettings.fontSize * 0.5;
756
+ var height = rows.length * (parent.activeObj.textSettings.fontSize + parent.activeObj.textSettings.fontSize * 0.25);
757
+ parent.notify('selection', { prop: 'setTextSelection', onPropertyChange: false,
758
+ value: { width: width, height: height } });
759
+ parent.notify('draw', { prop: 'updateActiveObject', onPropertyChange: false, value: { actPoint: parent.activeObj.activePoint, obj: parent.activeObj,
760
+ isMouseMove: null, x: null, y: null } });
761
+ parent.notify('selection', { prop: 'redrawShape', onPropertyChange: false,
762
+ value: { obj: parent.activeObj } });
763
+ };
764
+ Shape.prototype.updateTextFromTextArea = function () {
765
+ var parent = this.parent;
766
+ if (parent.activeObj.keyHistory !== parent.textArea.value) {
767
+ var prevCropObj = extend({}, parent.cropObj, {}, true);
768
+ var object = { currObj: {} };
769
+ parent.notify('filter', { prop: 'getCurrentObj', onPropertyChange: false, value: { object: object } });
770
+ var prevObj = object['currObj'];
771
+ prevObj.objColl = extend([], parent.objColl, [], true);
772
+ prevObj.pointColl = extend([], parent.pointColl, [], true);
773
+ prevObj.afterCropActions = extend([], this.parent.afterCropActions, [], true);
774
+ var selPointCollObj = { selPointColl: null };
775
+ parent.notify('freehand-draw', { prop: 'getSelPointColl', onPropertyChange: false,
776
+ value: { obj: selPointCollObj } });
777
+ prevObj.selPointColl = extend([], selPointCollObj['selPointColl'], [], true);
778
+ parent.notify('undo-redo', { prop: 'updateUndoRedoColl', onPropertyChange: false,
779
+ value: { operation: 'text', previousObj: prevObj, previousObjColl: prevObj.objColl,
780
+ previousPointColl: prevObj.pointColl, previousSelPointColl: prevObj.selPointColl,
781
+ previousCropObj: prevCropObj, previousText: parent.activeObj.keyHistory,
782
+ currentText: parent.textArea.value, previousFilter: null, isCircleCrop: null } });
783
+ }
784
+ parent.activeObj.keyHistory = parent.textArea.value;
785
+ parent.textArea.style.display = 'none';
786
+ parent.textArea.value = '';
787
+ this.updateFontStyles();
788
+ var width = this.upperContext.measureText(parent.activeObj.keyHistory).width +
789
+ parent.activeObj.textSettings.fontSize * 0.5;
790
+ var height = parent.activeObj.textSettings.fontSize + this.parent.activeObj.textSettings.fontSize * 0.25;
791
+ var rows = parent.activeObj.keyHistory.split('\n');
792
+ if (rows.length > 1) {
793
+ height *= rows.length;
794
+ var widthColl = [];
795
+ for (var i = 0, len = rows.length; i < len; i++) {
796
+ widthColl.push(this.upperContext.measureText(rows[i]).width +
797
+ parent.activeObj.textSettings.fontSize * 0.5);
798
+ }
799
+ width = Math.max.apply(Math, widthColl);
800
+ }
801
+ parent.notify('selection', { prop: 'setTextSelection', onPropertyChange: false,
802
+ value: { width: width, height: height } });
803
+ parent.notify('draw', { prop: 'updateActiveObject', onPropertyChange: false, value: { actPoint: parent.activeObj.activePoint, obj: parent.activeObj,
804
+ isMouseMove: null, x: null, y: null } });
805
+ this.updImgRatioForActObj();
806
+ };
807
+ Shape.prototype.iterateObjColl = function () {
808
+ var parent = this.parent;
809
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
810
+ this.apply(parent.objColl[i].shape, parent.objColl[i]);
811
+ this.refreshActiveObj();
812
+ }
813
+ };
814
+ Shape.prototype.updImgRatioForActObj = function () {
815
+ var parent = this.parent;
816
+ parent.activeObj.imageRatio = { startX: ((parent.activeObj.activePoint.startX - parent.img.destLeft) /
817
+ parent.img.destWidth),
818
+ startY: ((parent.activeObj.activePoint.startY - parent.img.destTop) / parent.img.destHeight),
819
+ endX: ((parent.activeObj.activePoint.endX - parent.img.destLeft) / parent.img.destWidth),
820
+ endY: ((parent.activeObj.activePoint.endY - parent.img.destTop) / parent.img.destHeight),
821
+ width: parent.img.destWidth / parent.activeObj.activePoint.width, height: parent.img.destHeight /
822
+ parent.activeObj.activePoint.height };
823
+ if (parent.activeObj.rotationCirclePointColl) {
824
+ parent.activeObj.rotationCirclePointColl.ratioX = (parent.activeObj.rotationCirclePointColl.x -
825
+ parent.img.destLeft) / parent.img.destWidth;
826
+ parent.activeObj.rotationCirclePointColl.ratioY = (parent.activeObj.rotationCirclePointColl.y -
827
+ parent.img.destTop) / parent.img.destHeight;
828
+ }
829
+ if (parent.activeObj.shape === 'path') {
830
+ this.updatePathRatio(parent.activeObj);
831
+ }
832
+ else if (parent.activeObj.shape === 'arrow') {
833
+ this.updateArrowRatio(parent.activeObj);
834
+ }
835
+ };
836
+ Shape.prototype.zoomObjColl = function (preventApply) {
837
+ var parent = this.parent;
838
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
839
+ var currObj = parent.objColl[i];
840
+ currObj.activePoint.startX = (currObj.imageRatio.startX * parent.img.destWidth) + parent.img.destLeft;
841
+ currObj.activePoint.startY = (currObj.imageRatio.startY * parent.img.destHeight) + parent.img.destTop;
842
+ currObj.activePoint.endX = (currObj.imageRatio.endX * parent.img.destWidth) + parent.img.destLeft;
843
+ currObj.activePoint.endY = (currObj.imageRatio.endY * parent.img.destHeight) + parent.img.destTop;
844
+ currObj = this.updateWidthHeight(currObj);
845
+ if (currObj.shape === 'text') {
846
+ this.updateFontSize(currObj);
847
+ }
848
+ else if (currObj.shape === 'line' || currObj.shape === 'arrow') {
849
+ currObj.pointColl = this.getLinePoints(currObj.activePoint.startX, currObj.activePoint.startY, currObj.activePoint.endX, currObj.activePoint.endY);
850
+ for (var n = 0, len_1 = currObj.pointColl.length; n < len_1; n++) {
851
+ currObj.pointColl[n].ratioX =
852
+ (currObj.pointColl[n].x - parent.img.destLeft) / parent.img.destWidth;
853
+ currObj.pointColl[n].ratioY =
854
+ (currObj.pointColl[n].y - parent.img.destTop) / parent.img.destHeight;
855
+ }
856
+ if (currObj.shape === 'arrow') {
857
+ this.updateArrowSize(currObj);
858
+ }
859
+ }
860
+ else if (currObj.shape === 'path') {
861
+ for (var l = 0, len_2 = currObj.pointColl.length; l < len_2; l++) {
862
+ currObj.pointColl[l].x = (currObj.pointColl[l].ratioX * parent.img.destWidth)
863
+ + parent.img.destLeft;
864
+ currObj.pointColl[l].y = (currObj.pointColl[l].ratioY * parent.img.destHeight) +
865
+ parent.img.destTop;
866
+ }
867
+ this.updatePathRatio(currObj);
868
+ }
869
+ parent.notify('draw', { prop: 'updateActiveObject', onPropertyChange: false, value: { actPoint: currObj.activePoint,
870
+ obj: currObj } });
871
+ if (isNullOrUndefined(preventApply)) {
872
+ var temp = this.lowerContext.filter;
873
+ this.lowerContext.filter = 'none';
874
+ this.apply(currObj.shape, currObj);
875
+ this.refreshActiveObj();
876
+ this.lowerContext.filter = temp;
877
+ }
878
+ if (currObj.shape !== 'line' && currObj.shape !== 'arrow' && currObj.shape !== 'path' && currObj.rotatedAngle !== 0) {
879
+ this.setPointCollForShapeRotation(currObj);
880
+ currObj.rotationCirclePoint.x =
881
+ (currObj.rotationCirclePoint.ratioX * parent.img.destWidth) + parent.img.destLeft;
882
+ currObj.rotationCirclePoint.y =
883
+ (currObj.rotationCirclePoint.ratioY * parent.img.destHeight) + parent.img.destTop;
884
+ currObj.rotationCirclePointColl.x =
885
+ (currObj.rotationCirclePointColl.ratioX * parent.img.destWidth) +
886
+ parent.img.destLeft;
887
+ currObj.rotationCirclePointColl.y =
888
+ (currObj.rotationCirclePointColl.ratioY * parent.img.destHeight) +
889
+ parent.img.destTop;
890
+ }
891
+ }
892
+ };
893
+ Shape.prototype.redrawObj = function (degree) {
894
+ var parent = this.parent;
895
+ if (this.parent.objColl.length > 0) {
896
+ if (degree === 'horizontal' || degree === 'vertical' || degree === 'Horizontal' || degree === 'Vertical' ||
897
+ degree === 'horizontalVertical' || degree === 'verticalHorizontal') {
898
+ this.updateCurrentActiveObjPoint(degree.toLowerCase());
899
+ }
900
+ else if (typeof (degree) === 'number') {
901
+ this.updateCurrentActiveObjPoint(degree);
902
+ var tempFilter = this.lowerContext.filter;
903
+ this.lowerContext.filter = 'brightness(' + 1 + ') ' + 'contrast(' + 100 + '%) ' + 'hue-rotate(' + 0 + 'deg) ' +
904
+ 'saturate(' + 100 + '%) ' + 'opacity(' + 1 + ') ' + 'blur(' + 0 + 'px) ' + 'sepia(0%) ' + 'grayscale(0%) ' + 'invert(0%)';
905
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
906
+ var splitWords = parent.objColl[i].shape.split('-');
907
+ if (splitWords[0] !== 'crop') {
908
+ this.apply(parent.objColl[i].shape, parent.objColl[i]);
909
+ }
910
+ }
911
+ this.lowerContext.filter = tempFilter;
912
+ }
913
+ }
914
+ };
915
+ Shape.prototype.updateCurrentActiveObjPoint = function (degree) {
916
+ var parent = this.parent;
917
+ var currActObjIndex;
918
+ for (var index = 0, len = parent.objColl.length; index < len; index++) {
919
+ var currObj = parent.objColl[index];
920
+ if (parent.activeObj.shape === currObj.shape &&
921
+ parent.activeObj.activePoint.startX === currObj.activePoint.startX &&
922
+ parent.activeObj.activePoint.startY === currObj.activePoint.startY &&
923
+ parent.activeObj.activePoint.endX === currObj.activePoint.endX &&
924
+ parent.activeObj.activePoint.endY === currObj.activePoint.endY &&
925
+ parent.activeObj.currIndex === currObj.currIndex) {
926
+ currActObjIndex = index;
927
+ break;
928
+ }
929
+ }
930
+ if (degree === 'horizontal' || degree === 'vertical' || degree === 'Horizontal' || degree === 'Vertical' ||
931
+ degree === 'horizontalvertical' || degree === 'verticalhorizontal') {
932
+ if (degree === 'horizontal' || degree === 'Horizontal') {
933
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
934
+ var currObj = parent.objColl[i];
935
+ if (currObj.shapeFlip !== parent.transform.currFlipState) {
936
+ if (currObj.activePoint.startX <= parent.img.destLeft + (parent.img.destWidth / 2)) {
937
+ currObj.activePoint.endX = (parent.img.destLeft + parent.img.destWidth) - (currObj.activePoint.startX -
938
+ parent.img.destLeft);
939
+ currObj.activePoint.startX = currObj.activePoint.endX - currObj.activePoint.width;
940
+ parent.notify('draw', { prop: 'updateActiveObject', onPropertyChange: false, value: { actPoint: currObj.activePoint, obj: currObj } });
941
+ }
942
+ else if (currObj.activePoint.startX >= parent.img.destLeft + (parent.img.destWidth / 2)) {
943
+ currObj.activePoint.startX = parent.img.destLeft + (parent.img.destLeft + parent.img.destWidth -
944
+ currObj.activePoint.endX);
945
+ currObj.activePoint.endX = currObj.activePoint.startX + currObj.activePoint.width;
946
+ parent.notify('draw', { prop: 'updateActiveObject', onPropertyChange: false, value: { actPoint: currObj.activePoint,
947
+ obj: currObj } });
948
+ }
949
+ if (currObj.shape === 'line' || currObj.shape === 'arrow' || currObj.shape === 'path') {
950
+ this.flipLineArrowObj(currObj, 'horizontal');
951
+ }
952
+ else if (currObj.rotatedAngle !== 0) {
953
+ currObj.rotatedAngle = currObj.rotatedAngle + (Math.PI - currObj.rotatedAngle) * 2;
954
+ if (currObj.rotationCirclePointColl.x <= parent.img.destLeft + (parent.img.destWidth / 2)) {
955
+ currObj.rotationCirclePointColl.x = (parent.img.destLeft + parent.img.destWidth) -
956
+ (currObj.rotationCirclePointColl.x - parent.img.destLeft);
957
+ }
958
+ else if (currObj.rotationCirclePointColl.x >= parent.img.destLeft + (parent.img.destWidth / 2)) {
959
+ currObj.rotationCirclePointColl.x = parent.img.destLeft +
960
+ (parent.img.destLeft + parent.img.destWidth - currObj.rotationCirclePointColl.x);
961
+ }
962
+ currObj.rotationCirclePointColl.ratioX =
963
+ (currObj.rotationCirclePointColl.x - parent.img.destLeft) / parent.img.destWidth;
964
+ }
965
+ currObj.shapeFlip = parent.transform.currFlipState;
966
+ currObj.imageRatio = { startX: ((currObj.activePoint.startX - parent.img.destLeft) / parent.img.destWidth),
967
+ startY: ((currObj.activePoint.startY - parent.img.destTop) / parent.img.destHeight),
968
+ endX: ((currObj.activePoint.endX - parent.img.destLeft) / parent.img.destWidth),
969
+ endY: ((currObj.activePoint.endY - parent.img.destTop) / parent.img.destHeight),
970
+ width: parent.img.destWidth / currObj.activePoint.width,
971
+ height: parent.img.destHeight / currObj.activePoint.height };
972
+ }
973
+ }
974
+ }
975
+ else if (degree === 'vertical' || degree === 'Vertical') {
976
+ for (var i = 0; i < parent.objColl.length; i++) {
977
+ var currObj = parent.objColl[i];
978
+ if (currObj.shapeFlip !== parent.transform.currFlipState) {
979
+ if (currObj.activePoint.startY <= parent.img.destTop + (parent.img.destHeight / 2)) {
980
+ currObj.activePoint.endY = (parent.img.destTop + parent.img.destHeight) -
981
+ (currObj.activePoint.startY - parent.img.destTop);
982
+ currObj.activePoint.startY = currObj.activePoint.endY - currObj.activePoint.height;
983
+ parent.notify('draw', { prop: 'updateActiveObject', onPropertyChange: false, value: { actPoint: currObj.activePoint,
984
+ obj: currObj } });
985
+ }
986
+ else if (currObj.activePoint.startY >= this.parent.lowerCanvas.height / 2) {
987
+ currObj.activePoint.startY = parent.img.destTop + (parent.img.destTop +
988
+ parent.img.destHeight - currObj.activePoint.endY);
989
+ currObj.activePoint.endY = currObj.activePoint.startY +
990
+ currObj.activePoint.height;
991
+ parent.notify('draw', { prop: 'updateActiveObject', onPropertyChange: false, value: { actPoint: currObj.activePoint,
992
+ obj: currObj } });
993
+ }
994
+ if (currObj.shape === 'line' || currObj.shape === 'arrow' ||
995
+ currObj.shape === 'path') {
996
+ this.flipLineArrowObj(currObj, 'vertical');
997
+ }
998
+ else if (currObj.rotatedAngle !== 0) {
999
+ currObj.rotatedAngle = -currObj.rotatedAngle;
1000
+ if (currObj.rotationCirclePointColl.y <= parent.img.destTop + (parent.img.destHeight / 2)) {
1001
+ currObj.rotationCirclePointColl.y = (parent.img.destTop + parent.img.destHeight) -
1002
+ (currObj.rotationCirclePointColl.y - parent.img.destTop);
1003
+ }
1004
+ else if (currObj.rotationCirclePointColl.y >= parent.img.destTop +
1005
+ (parent.img.destHeight / 2)) {
1006
+ currObj.rotationCirclePointColl.y = parent.img.destTop + (parent.img.destTop +
1007
+ parent.img.destHeight - currObj.rotationCirclePointColl.y);
1008
+ }
1009
+ currObj.rotationCirclePointColl.ratioY =
1010
+ (currObj.rotationCirclePointColl.y - parent.img.destTop) / parent.img.destHeight;
1011
+ }
1012
+ currObj.shapeFlip = parent.transform.currFlipState;
1013
+ currObj.imageRatio = { startX: ((currObj.activePoint.startX - parent.img.destLeft) / parent.img.destWidth),
1014
+ startY: ((currObj.activePoint.startY - parent.img.destTop) / parent.img.destHeight),
1015
+ endX: ((currObj.activePoint.endX - parent.img.destLeft) / parent.img.destWidth),
1016
+ endY: ((currObj.activePoint.endY - parent.img.destTop) / parent.img.destHeight),
1017
+ width: parent.img.destWidth / currObj.activePoint.width,
1018
+ height: parent.img.destHeight / currObj.activePoint.height };
1019
+ }
1020
+ }
1021
+ }
1022
+ else if (degree === 'verticalhorizontal' || degree === 'horizontalvertical') {
1023
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
1024
+ var currObj = parent.objColl[i];
1025
+ if (currObj.shapeFlip !== parent.transform.currFlipState) {
1026
+ if (currObj.activePoint.startX <= parent.img.destLeft + (parent.img.destWidth / 2)) {
1027
+ currObj.activePoint.endX = (parent.img.destLeft + parent.img.destWidth) - (currObj.activePoint.startX -
1028
+ parent.img.destLeft);
1029
+ currObj.activePoint.startX = currObj.activePoint.endX - currObj.activePoint.width;
1030
+ parent.notify('draw', { prop: 'updateActiveObject', onPropertyChange: false, value: { actPoint: currObj.activePoint, obj: currObj } });
1031
+ }
1032
+ else if (currObj.activePoint.startX >= parent.img.destLeft + (parent.img.destWidth / 2)) {
1033
+ currObj.activePoint.startX = parent.img.destLeft + (parent.img.destLeft +
1034
+ parent.img.destWidth - currObj.activePoint.endX);
1035
+ currObj.activePoint.endX = currObj.activePoint.startX + currObj.activePoint.width;
1036
+ parent.notify('draw', { prop: 'updateActiveObject', onPropertyChange: false, value: { actPoint: currObj.activePoint, obj: currObj } });
1037
+ }
1038
+ if (currObj.activePoint.startY <= parent.img.destTop + (parent.img.destHeight / 2)) {
1039
+ currObj.activePoint.endY = (parent.img.destTop + parent.img.destHeight) -
1040
+ (currObj.activePoint.startY - parent.img.destTop);
1041
+ currObj.activePoint.startY = currObj.activePoint.endY -
1042
+ currObj.activePoint.height;
1043
+ parent.notify('draw', { prop: 'updateActiveObject', onPropertyChange: false, value: { actPoint: currObj.activePoint, obj: currObj } });
1044
+ }
1045
+ else if (currObj.activePoint.startY >= this.parent.lowerCanvas.height / 2) {
1046
+ currObj.activePoint.startY = parent.img.destTop + (parent.img.destTop +
1047
+ parent.img.destHeight - currObj.activePoint.endY);
1048
+ currObj.activePoint.endY = currObj.activePoint.startY +
1049
+ currObj.activePoint.height;
1050
+ parent.notify('draw', { prop: 'updateActiveObject', onPropertyChange: false, value: { actPoint: currObj.activePoint, obj: currObj } });
1051
+ }
1052
+ if (currObj.shape === 'line' || currObj.shape === 'arrow' || currObj.shape === 'path') {
1053
+ this.flipLineArrowObj(currObj, degree);
1054
+ }
1055
+ currObj.shapeFlip = parent.transform.currFlipState;
1056
+ currObj.imageRatio = { startX: ((currObj.activePoint.startX - parent.img.destLeft) / parent.img.destWidth),
1057
+ startY: ((currObj.activePoint.startY - parent.img.destTop) / parent.img.destHeight),
1058
+ endX: ((currObj.activePoint.endX - parent.img.destLeft) / parent.img.destWidth),
1059
+ endY: ((currObj.activePoint.endY - parent.img.destTop) / parent.img.destHeight),
1060
+ width: parent.img.destWidth / currObj.activePoint.width,
1061
+ height: parent.img.destHeight / currObj.activePoint.height };
1062
+ }
1063
+ }
1064
+ }
1065
+ if (currActObjIndex !== undefined) {
1066
+ parent.activeObj = extend({}, parent.objColl[currActObjIndex], {}, true);
1067
+ }
1068
+ }
1069
+ else if (degree === 90) {
1070
+ this.rotateObjColl();
1071
+ }
1072
+ else if (degree === -90) {
1073
+ for (var i = 0; i < 3; i++) {
1074
+ this.rotateObjColl();
1075
+ }
1076
+ }
1077
+ else if (typeof (degree) === 'number') {
1078
+ if (degree > 0) {
1079
+ this.rotateObjColl();
1080
+ }
1081
+ else {
1082
+ for (var i = 0; i < 3; i++) {
1083
+ this.rotateObjColl();
1084
+ }
1085
+ }
1086
+ }
1087
+ };
1088
+ Shape.prototype.rotateObjColl = function () {
1089
+ var parent = this.parent;
1090
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
1091
+ var currObj = parent.objColl[i];
1092
+ currObj.activePoint.startY = parent.img.destTop + (parent.img.destHeight * currObj.imageRatio.startX);
1093
+ currObj.activePoint.endY = parent.img.destTop + (parent.img.destHeight * currObj.imageRatio.endX);
1094
+ currObj.activePoint.startX = (parent.img.destLeft + parent.img.destWidth) -
1095
+ (parent.img.destWidth * currObj.imageRatio.endY);
1096
+ currObj.activePoint.endX = (parent.img.destLeft + parent.img.destWidth) -
1097
+ (parent.img.destWidth * currObj.imageRatio.startY);
1098
+ currObj = this.updateWidthHeight(parent.objColl[i]);
1099
+ this.updateFontSize(currObj);
1100
+ if (currObj.shape === 'line' || currObj.shape === 'arrow' ||
1101
+ currObj.shape === 'path') {
1102
+ this.rotateLineArrowObj(currObj);
1103
+ if (currObj.shape === 'arrow') {
1104
+ this.updateArrowSize(currObj);
1105
+ }
1106
+ }
1107
+ else if (currObj.rotatedAngle !== 0) {
1108
+ currObj.rotationCirclePointColl.y = parent.img.destTop + (parent.img.destHeight * currObj.rotationCirclePointColl.ratioX);
1109
+ currObj.rotationCirclePointColl.x = (parent.img.destLeft + parent.img.destWidth) -
1110
+ (parent.img.destWidth * currObj.rotationCirclePointColl.ratioY);
1111
+ currObj.rotationCirclePointColl.ratioX = (currObj.rotationCirclePointColl.x
1112
+ - parent.img.destLeft) / parent.img.destWidth;
1113
+ currObj.rotationCirclePointColl.ratioY = (currObj.rotationCirclePointColl.y
1114
+ - parent.img.destTop) / parent.img.destHeight;
1115
+ }
1116
+ }
1117
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
1118
+ parent.notify('draw', { prop: 'updateActiveObject', onPropertyChange: false, value: { actPoint: parent.objColl[i].activePoint, obj: parent.objColl[i] } });
1119
+ }
1120
+ // Update current image ratio for all objects
1121
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
1122
+ var currObj = parent.objColl[i];
1123
+ currObj.imageRatio = { startX: ((currObj.activePoint.startX - parent.img.destLeft) / parent.img.destWidth),
1124
+ startY: ((currObj.activePoint.startY - parent.img.destTop) / parent.img.destHeight),
1125
+ endX: ((currObj.activePoint.endX - parent.img.destLeft) / parent.img.destWidth),
1126
+ endY: ((currObj.activePoint.endY - parent.img.destTop) / parent.img.destHeight),
1127
+ width: parent.img.destWidth / currObj.activePoint.width,
1128
+ height: parent.img.destHeight / currObj.activePoint.height };
1129
+ }
1130
+ };
1131
+ Shape.prototype.rotateLineArrowObj = function (obj) {
1132
+ if (isNullOrUndefined(obj.pointColl)) {
1133
+ return;
1134
+ }
1135
+ var parent = this.parent;
1136
+ if (obj.pointColl.length > 0) {
1137
+ for (var n = 0; n < obj.pointColl.length; n++) {
1138
+ obj.pointColl[n].y = parent.img.destTop + (parent.img.destHeight * obj.pointColl[n].ratioX);
1139
+ obj.pointColl[n].x = (parent.img.destLeft + parent.img.destWidth) - (parent.img.destWidth *
1140
+ obj.pointColl[n].ratioY);
1141
+ }
1142
+ for (var n = 0; n < obj.pointColl.length; n++) {
1143
+ obj.pointColl[n].ratioX = (obj.pointColl[n].x - parent.img.destLeft) / parent.img.destWidth;
1144
+ obj.pointColl[n].ratioY = (obj.pointColl[n].y - parent.img.destTop) / parent.img.destHeight;
1145
+ }
1146
+ var prevPoint = void 0;
1147
+ if (isNullOrUndefined(obj.pointColl[obj.pointColl.length - 2])) {
1148
+ prevPoint = { x: 0, y: 0 };
1149
+ }
1150
+ else {
1151
+ prevPoint = { x: obj.pointColl[obj.pointColl.length - 2].x, y: obj.pointColl[obj.pointColl.length - 2].y };
1152
+ }
1153
+ var diffX = obj.pointColl[obj.pointColl.length - 1].x - prevPoint.x;
1154
+ var diffY = obj.pointColl[obj.pointColl.length - 1].y - prevPoint.y;
1155
+ obj.activePoint.startX = obj.pointColl[0].x;
1156
+ obj.activePoint.startY = obj.pointColl[0].y;
1157
+ obj.activePoint.endX = obj.pointColl[obj.pointColl.length - 1].x + (diffX / 2);
1158
+ obj.activePoint.endY = obj.pointColl[obj.pointColl.length - 1].y + (diffY / 2);
1159
+ obj = this.updateWidthHeight(obj);
1160
+ }
1161
+ };
1162
+ Shape.prototype.flipLineArrowObj = function (obj, value) {
1163
+ if (isNullOrUndefined(obj.pointColl)) {
1164
+ return;
1165
+ }
1166
+ if (value.toLowerCase() === 'horizontal') {
1167
+ this.lineArrowHorizontalFlip(obj);
1168
+ }
1169
+ else if (value.toLowerCase() === 'vertical') {
1170
+ this.lineArrowVerticalFlip(obj);
1171
+ }
1172
+ else {
1173
+ this.lineArrowHorizontalFlip(obj);
1174
+ obj.shapeFlip = '';
1175
+ this.lineArrowVerticalFlip(obj);
1176
+ }
1177
+ obj.activePoint.startX = obj.pointColl[0].x;
1178
+ obj.activePoint.startY = obj.pointColl[0].y;
1179
+ obj.activePoint.endX = obj.pointColl[obj.pointColl.length - 1].x;
1180
+ obj.activePoint.endY = obj.pointColl[obj.pointColl.length - 1].y;
1181
+ if (obj.activePoint.startX > obj.activePoint.endX) {
1182
+ var temp = obj.activePoint.startX;
1183
+ obj.activePoint.startX = obj.activePoint.endX;
1184
+ obj.activePoint.endX = temp;
1185
+ temp = obj.activePoint.startY;
1186
+ obj.activePoint.startY = obj.activePoint.endY;
1187
+ obj.activePoint.endY = temp;
1188
+ }
1189
+ };
1190
+ Shape.prototype.lineArrowHorizontalFlip = function (obj) {
1191
+ var parent = this.parent;
1192
+ // Update flip value for point collection
1193
+ if (obj.shapeFlip !== parent.transform.currFlipState) {
1194
+ for (var l = 0, len = obj.pointColl.length; l < len; l++) {
1195
+ var currPoint = obj.pointColl[l];
1196
+ if (currPoint.x <= parent.img.destLeft + (parent.img.destWidth / 2)) {
1197
+ currPoint.x = (parent.img.destLeft + parent.img.destWidth) - (currPoint.x
1198
+ - parent.img.destLeft);
1199
+ }
1200
+ else if (currPoint.x >= parent.img.destLeft + (parent.img.destWidth / 2)) {
1201
+ currPoint.x = parent.img.destLeft + (parent.img.destLeft + parent.img.destWidth -
1202
+ currPoint.x);
1203
+ }
1204
+ currPoint.ratioX = (currPoint.x - parent.img.destLeft) / parent.img.destWidth;
1205
+ currPoint.ratioY = (currPoint.y - parent.img.destTop) / parent.img.destHeight;
1206
+ }
1207
+ if (obj.shape === 'arrow') {
1208
+ var value = obj.start;
1209
+ obj.start = obj.end;
1210
+ obj.end = value;
1211
+ }
1212
+ obj.shapeFlip = parent.transform.currFlipState;
1213
+ }
1214
+ };
1215
+ Shape.prototype.lineArrowVerticalFlip = function (obj) {
1216
+ var parent = this.parent;
1217
+ // Update flip value for point collection
1218
+ if (obj.shapeFlip !== parent.transform.currFlipState) {
1219
+ for (var l = 0, len = obj.pointColl.length; l < len; l++) {
1220
+ var currPoint = obj.pointColl[l];
1221
+ if (currPoint.y <= parent.img.destTop + (parent.img.destHeight / 2)) {
1222
+ currPoint.y = (parent.img.destTop + parent.img.destHeight) -
1223
+ (currPoint.y - parent.img.destTop);
1224
+ }
1225
+ else if (currPoint.y >= parent.img.destTop + (parent.img.destHeight / 2)) {
1226
+ currPoint.y = parent.img.destTop + (parent.img.destTop + parent.img.destHeight -
1227
+ currPoint.y);
1228
+ }
1229
+ currPoint.ratioX = (currPoint.x - parent.img.destLeft) / parent.img.destWidth;
1230
+ currPoint.ratioY = (currPoint.y - parent.img.destTop) / parent.img.destHeight;
1231
+ }
1232
+ obj.shapeFlip = parent.transform.currFlipState;
1233
+ }
1234
+ };
1235
+ Shape.prototype.getRotDegOfShape = function (obj) {
1236
+ var degree;
1237
+ if (obj.shapeDegree === 0) {
1238
+ degree = this.parent.transform.degree;
1239
+ }
1240
+ else {
1241
+ degree = this.parent.transform.degree - obj.shapeDegree;
1242
+ }
1243
+ if (degree < 0) {
1244
+ degree = 360 + degree;
1245
+ }
1246
+ return degree;
1247
+ };
1248
+ Shape.prototype.renderTextArea = function (x, y, actObj) {
1249
+ var parent = this.parent;
1250
+ var degree = this.getRotDegOfShape(parent.activeObj);
1251
+ this.transformTextArea();
1252
+ if (!isBlazor()) {
1253
+ parent.notify('toolbar', { prop: 'destroy-qa-toolbar', onPropertyChange: false });
1254
+ }
1255
+ else {
1256
+ parent.updateToolbar(parent.element, 'destroyQuickAccessToolbar');
1257
+ }
1258
+ if (parent.element.querySelector('#' + parent.element.id + '_duplicate')) {
1259
+ parent.element.querySelector('#' + parent.element.id + '_duplicate').classList.add('e-disabled');
1260
+ }
1261
+ if (parent.element.querySelector('#' + parent.element.id + '_remove')) {
1262
+ parent.element.querySelector('#' + parent.element.id + '_remove').classList.add('e-disabled');
1263
+ }
1264
+ if (parent.element.querySelector('#' + parent.element.id + '_editText')) {
1265
+ parent.element.querySelector('#' + parent.element.id + '_editText').classList.add('e-disabled');
1266
+ }
1267
+ parent.textArea.style.display = 'block';
1268
+ parent.textArea.style.left = x + 'px';
1269
+ parent.textArea.style.top = y + 'px';
1270
+ parent.textArea.style.fontFamily = actObj.textSettings.fontFamily;
1271
+ parent.textArea.style.fontSize = actObj.textSettings.fontSize + 'px';
1272
+ parent.textArea.style.color = actObj.strokeSettings.strokeColor;
1273
+ parent.textArea.style.fontWeight = actObj.textSettings.bold ? 'bold' : 'normal';
1274
+ parent.textArea.style.fontStyle = actObj.textSettings.italic ? 'italic' : 'normal';
1275
+ parent.textArea.style.border = '2px solid ' + parent.themeColl[parent.theme]['primaryColor'];
1276
+ parent.textArea.value = actObj.keyHistory;
1277
+ parent.textArea.style.overflow = 'hidden';
1278
+ parent.textArea.style.width = 'auto';
1279
+ parent.textArea.style.height = 'auto';
1280
+ parent.textArea.focus();
1281
+ var zoomFactor = parent.transform.zoomFactor;
1282
+ var _a = actObj.activePoint, width = _a.width, height = _a.height;
1283
+ if (degree % 90 === 0 && degree % 180 !== 0 && degree !== 0) {
1284
+ parent.textArea.style.width = (zoomFactor === 0 ? height : height) + 'px';
1285
+ parent.textArea.style.height = (zoomFactor === 0 ? width : width) + 'px';
1286
+ }
1287
+ else {
1288
+ parent.textArea.style.width = (zoomFactor === 0 ? width : width) + 'px';
1289
+ parent.textArea.style.height = (zoomFactor === 0 ? height : height) + 'px';
1290
+ }
1291
+ this.setTextBoxWidth();
1292
+ var obj = { flipColl: null };
1293
+ parent.notify('transform', { prop: 'getFlipColl', onPropertyChange: false, value: { obj: obj } });
1294
+ if (obj['flipColl'].length <= 1) {
1295
+ this.setTextBoxHeight();
1296
+ }
1297
+ if (degree % 90 === 0 && degree % 180 !== 0) {
1298
+ if (parseFloat(parent.textArea.style.left) + parseFloat(parent.textArea.style.width) > parent.img.destTop +
1299
+ parent.img.destHeight) {
1300
+ this.alignTextAreaIntoCanvas();
1301
+ }
1302
+ }
1303
+ else {
1304
+ if (parseFloat(parent.textArea.style.left) + parseFloat(parent.textArea.style.width) > parent.img.destLeft +
1305
+ parent.img.destWidth) {
1306
+ this.alignTextAreaIntoCanvas();
1307
+ }
1308
+ }
1309
+ parent.notify('selection', { prop: 'clearUpperCanvas', onPropertyChange: false });
1310
+ };
1311
+ Shape.prototype.setTextBoxWidth = function (e) {
1312
+ var parent = this.parent;
1313
+ var text = this.getMaxText(true);
1314
+ if (parent.textArea.style.display === 'block') {
1315
+ this.updateFontStyles(true);
1316
+ }
1317
+ else {
1318
+ this.updateFontStyles();
1319
+ }
1320
+ var textAreaWidth = (this.upperContext.measureText(text).width + (parseFloat(parent.textArea.style.fontSize) / 2));
1321
+ var letterWidth = e ? this.upperContext.measureText(String.fromCharCode(e.which)).width : 0;
1322
+ var actObj = extend({}, parent.activeObj, {}, true);
1323
+ var flip = '';
1324
+ var degree = this.getRotDegOfShape(actObj);
1325
+ if (actObj.shapeFlip !== parent.transform.currFlipState) {
1326
+ flip = '';
1327
+ }
1328
+ else {
1329
+ flip = parent.transform.currFlipState;
1330
+ }
1331
+ if ((e && parseFloat(parent.textArea.style.width) < (textAreaWidth + letterWidth)) || isNullOrUndefined(e)) {
1332
+ if (degree === 0) {
1333
+ if (flip.toLowerCase() === 'horizontal') {
1334
+ if ((parseFloat(parent.textArea.style.left) - parent.img.destLeft) - textAreaWidth - letterWidth > 0) {
1335
+ parent.textArea.style.width = (textAreaWidth + letterWidth) + 'px';
1336
+ }
1337
+ }
1338
+ else if ((parent.img.destWidth - (parseFloat(parent.textArea.style.left) -
1339
+ parent.img.destLeft)) > (textAreaWidth + letterWidth)) {
1340
+ parent.textArea.style.width = (textAreaWidth + letterWidth) + 'px';
1341
+ }
1342
+ }
1343
+ else if (degree === 90) {
1344
+ if (flip.toLowerCase() === 'vertical') {
1345
+ if ((parseFloat(parent.textArea.style.top) - parent.img.destTop) - textAreaWidth - letterWidth > 0) {
1346
+ parent.textArea.style.width = (textAreaWidth + letterWidth) + 'px';
1347
+ }
1348
+ }
1349
+ else if ((parent.img.destHeight - (parseFloat(parent.textArea.style.top) -
1350
+ parent.img.destTop)) > (textAreaWidth + letterWidth)) {
1351
+ parent.textArea.style.width = (textAreaWidth + letterWidth) + 'px';
1352
+ }
1353
+ }
1354
+ else if (degree === 180) {
1355
+ var textAreaLeft = parseFloat(parent.textArea.style.left);
1356
+ var destLeft = parent.img.destLeft;
1357
+ if (flip.toLowerCase() === 'horizontal') {
1358
+ var remainingWidth = parent.img.destWidth - (textAreaLeft - destLeft);
1359
+ if (remainingWidth > textAreaWidth + letterWidth) {
1360
+ parent.textArea.style.width = (textAreaWidth + letterWidth) + 'px';
1361
+ }
1362
+ }
1363
+ else {
1364
+ var distanceToLeft = textAreaLeft - destLeft;
1365
+ if (distanceToLeft - textAreaWidth - letterWidth > 0) {
1366
+ parent.textArea.style.width = (textAreaWidth + letterWidth) + 'px';
1367
+ }
1368
+ }
1369
+ }
1370
+ else if (degree === 270) {
1371
+ var textAreaTop = parseFloat(parent.textArea.style.top);
1372
+ var destTop = parent.img.destTop;
1373
+ if (flip.toLowerCase() === 'vertical') {
1374
+ var remainingHeight = parent.img.destHeight - (textAreaTop - destTop);
1375
+ if (remainingHeight > textAreaWidth + letterWidth) {
1376
+ parent.textArea.style.width = (textAreaWidth + letterWidth) + 'px';
1377
+ }
1378
+ }
1379
+ else {
1380
+ var distanceToTop = textAreaTop - destTop;
1381
+ if (distanceToTop - textAreaWidth - letterWidth > 0) {
1382
+ parent.textArea.style.width = (textAreaWidth + letterWidth) + 'px';
1383
+ }
1384
+ }
1385
+ }
1386
+ }
1387
+ };
1388
+ Shape.prototype.setTextBoxHeight = function () {
1389
+ var parent = this.parent;
1390
+ var textAreaTop;
1391
+ var actObj = extend({}, parent.activeObj, {}, true);
1392
+ var flip = '';
1393
+ var degree = this.getRotDegOfShape(actObj);
1394
+ if (actObj.textFlip === parent.transform.currFlipState) {
1395
+ flip = '';
1396
+ }
1397
+ else if (actObj.textFlip === '') {
1398
+ flip = parent.transform.currFlipState;
1399
+ }
1400
+ else {
1401
+ flip = actObj.textFlip;
1402
+ }
1403
+ switch (degree) {
1404
+ case 0:
1405
+ if (flip.toLowerCase() === 'vertical') {
1406
+ parent.textArea.style.maxHeight = (parent.img.destHeight - (parent.img.destHeight -
1407
+ parseFloat(parent.textArea.style.top))) + 'px';
1408
+ }
1409
+ else {
1410
+ textAreaTop = parseFloat(parent.textArea.style.top) - parent.img.destTop;
1411
+ parent.textArea.style.maxHeight = (parent.img.destHeight - textAreaTop) + 'px';
1412
+ }
1413
+ break;
1414
+ case 90:
1415
+ if (flip.toLowerCase() === 'horizontal') {
1416
+ parent.textArea.style.maxHeight = (parent.img.destWidth - (parseFloat(parent.textArea.style.left) -
1417
+ parent.img.destLeft)) + 'px';
1418
+ }
1419
+ else {
1420
+ parent.textArea.style.maxHeight = (parseFloat(parent.textArea.style.left) - parent.img.destLeft) + 'px';
1421
+ }
1422
+ break;
1423
+ case 180:
1424
+ if (flip.toLowerCase() === 'vertical') {
1425
+ textAreaTop = parseFloat(parent.textArea.style.top) - parent.img.destTop;
1426
+ parent.textArea.style.maxHeight = (parent.img.destHeight - textAreaTop) + 'px';
1427
+ }
1428
+ else {
1429
+ parent.textArea.style.maxHeight = (parseFloat(parent.textArea.style.top) - parent.img.destTop) + 'px';
1430
+ }
1431
+ break;
1432
+ case 270:
1433
+ if (flip.toLowerCase() === 'horizontal') {
1434
+ parent.textArea.style.maxHeight = (parseFloat(parent.textArea.style.left) - parent.img.destLeft) + 'px';
1435
+ }
1436
+ else {
1437
+ parent.textArea.style.maxHeight = parent.img.destWidth - (parseFloat(parent.textArea.style.left)
1438
+ - parent.img.destLeft) + 'px';
1439
+ }
1440
+ break;
1441
+ }
1442
+ };
1443
+ Shape.prototype.updatePathRatio = function (obj) {
1444
+ var parent = this.parent;
1445
+ for (var i = 0, len = obj.pointColl.length; i < len; i++) {
1446
+ var currPoint = obj.pointColl[i];
1447
+ currPoint.ratioX = (currPoint.x - parent.img.destLeft) / parent.img.destWidth;
1448
+ currPoint.ratioY = (currPoint.y - parent.img.destTop) / parent.img.destHeight;
1449
+ }
1450
+ };
1451
+ Shape.prototype.stopPathDrawing = function (e) {
1452
+ var parent = this.parent;
1453
+ if (parent.activeObj.shape === 'path') {
1454
+ var obj = { shape: null };
1455
+ parent.notify('selection', { prop: 'getCurrentDrawingShape', value: { obj: obj } });
1456
+ if (obj['shape'] === 'path') {
1457
+ var prevCropObj = extend({}, this.parent.cropObj, {}, true);
1458
+ var object = { currObj: {} };
1459
+ this.parent.notify('filter', { prop: 'getCurrentObj', onPropertyChange: false, value: { object: object } });
1460
+ var prevObj = object['currObj'];
1461
+ prevObj.objColl = extend([], this.parent.objColl, [], true);
1462
+ prevObj.pointColl = extend([], this.parent.pointColl, [], true);
1463
+ prevObj.afterCropActions = extend([], this.parent.afterCropActions, [], true);
1464
+ var selPointCollObj = { selPointColl: null };
1465
+ this.parent.notify('freehand-draw', { prop: 'getSelPointColl', onPropertyChange: false,
1466
+ value: { obj: selPointCollObj } });
1467
+ prevObj.selPointColl = extend([], selPointCollObj['selPointColl'], [], true);
1468
+ parent.notify('selection', { prop: 'setCurrentDrawingShape', value: { value: '' } });
1469
+ parent.currObjType.isDragging = false;
1470
+ if (e.type !== 'touchstart') {
1471
+ parent.activeObj.pointColl.pop();
1472
+ }
1473
+ this.updatePathRatio(parent.activeObj);
1474
+ parent.notify('undo-redo', { prop: 'updateUndoRedoColl', onPropertyChange: false,
1475
+ value: { operation: 'shapeTransform', previousObj: prevObj, previousObjColl: prevObj.objColl,
1476
+ previousPointColl: prevObj.pointColl, previousSelPointColl: prevObj.selPointColl,
1477
+ previousCropObj: prevCropObj, previousText: null,
1478
+ currentText: null, previousFilter: null, isCircleCrop: null } });
1479
+ parent.notify('selection', { prop: 'mouseUpEventHandler', value: { e: e } });
1480
+ parent.notify('draw', { prop: 'setNewPath', value: { bool: true } });
1481
+ if (parent.objColl[parent.objColl.length - 1]) {
1482
+ parent.selectShape(parent.objColl[parent.objColl.length - 1].currIndex);
1483
+ }
1484
+ if (!isBlazor()) {
1485
+ parent.notify('toolbar', { prop: 'renderQAT', onPropertyChange: false, value: { isPenEdit: null } });
1486
+ }
1487
+ else {
1488
+ parent.updateToolbar(parent.element, 'quickAccessToolbar', parent.activeObj.shape);
1489
+ }
1490
+ }
1491
+ }
1492
+ };
1493
+ Shape.prototype.findTextTarget = function (e) {
1494
+ var parent = this.parent;
1495
+ if (parent.activeObj.shape !== 'text') {
1496
+ this.stopPathDrawing(e);
1497
+ return;
1498
+ }
1499
+ var x;
1500
+ var y;
1501
+ if (e.type === 'dblclick') {
1502
+ x = e.clientX;
1503
+ y = e.clientY;
1504
+ }
1505
+ else if (e.type === 'touchstart') {
1506
+ x = e.touches[0].clientX;
1507
+ y = e.touches[0].clientY;
1508
+ parent.notify('selection', { prop: 'setTouchEndPoint', onPropertyChange: false,
1509
+ value: { x: e.touches[0].clientX, y: e.touches[0].clientY } });
1510
+ }
1511
+ parent.notify('toolbar', { prop: 'setPreventZoomBtn', onPropertyChange: false, value: { isPrevent: true } });
1512
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: { type: 'text',
1513
+ isApplyBtn: null, isCropping: null, isZooming: null, cType: null } });
1514
+ parent.notify('toolbar', { prop: 'setPreventZoomBtn', onPropertyChange: false, value: { isPrevent: false } });
1515
+ parent.notify('toolbar', { prop: 'update-toolbar-items', onPropertyChange: false });
1516
+ if (!isNullOrUndefined(x) && !isNullOrUndefined(y)) {
1517
+ var bbox = this.parent.lowerCanvas.getBoundingClientRect();
1518
+ x -= bbox.left;
1519
+ y -= bbox.top;
1520
+ var flip = '';
1521
+ var degree = this.getRotDegOfShape(parent.activeObj);
1522
+ if (parent.activeObj.textFlip === '') {
1523
+ if (parent.activeObj.textFlip === parent.transform.currFlipState) {
1524
+ flip = '';
1525
+ }
1526
+ else {
1527
+ flip = parent.transform.currFlipState;
1528
+ }
1529
+ }
1530
+ else {
1531
+ if (parent.activeObj.textFlip === parent.transform.currFlipState) {
1532
+ flip = '';
1533
+ }
1534
+ else if (parent.transform.currFlipState === '') {
1535
+ flip = parent.activeObj.textFlip;
1536
+ }
1537
+ else {
1538
+ flip = parent.transform.currFlipState;
1539
+ }
1540
+ }
1541
+ var temp = void 0;
1542
+ if (parent.textArea.style.display === 'none') {
1543
+ temp = extend({}, parent.activeObj, {}, true);
1544
+ for (var i = 0; i < parent.objColl.length; i++) {
1545
+ if (JSON.stringify(parent.activeObj) === JSON.stringify(parent.objColl[i])) {
1546
+ parent.objColl.splice(i, 1);
1547
+ }
1548
+ }
1549
+ this.refreshActiveObj();
1550
+ this.upperContext.clearRect(0, 0, this.parent.upperCanvas.width, this.parent.upperCanvas.height);
1551
+ this.lowerContext.clearRect(0, 0, this.parent.upperCanvas.width, this.parent.upperCanvas.height);
1552
+ parent.notify('draw', { prop: 'redrawImgWithObj', onPropertyChange: false });
1553
+ if ((parent.currSelectionPoint && parent.currSelectionPoint.shape === 'crop-circle') || parent.isCircleCrop) {
1554
+ parent.notify('crop', { prop: 'cropCircle', onPropertyChange: false,
1555
+ value: { context: this.lowerContext, isSave: null, isFlip: null } });
1556
+ }
1557
+ parent.activeObj = temp;
1558
+ this.updateFontStyles();
1559
+ var actObj = extend({}, parent.activeObj, {}, true);
1560
+ if (x >= (actObj.activePoint.startX - (actObj.topLeftCircle.radius * 2)) &&
1561
+ x <= (actObj.activePoint.endX + (actObj.topLeftCircle.radius * 2)) &&
1562
+ y >= (actObj.activePoint.startY - (actObj.topLeftCircle.radius * 2)) &&
1563
+ y <= (actObj.activePoint.endY + (actObj.topLeftCircle.radius * 2))) {
1564
+ this.upperContext.clearRect(0, 0, this.parent.upperCanvas.width, this.parent.upperCanvas.height);
1565
+ if (actObj.flipObjColl.length === 4) {
1566
+ actObj.flipObjColl = [];
1567
+ flip = '';
1568
+ }
1569
+ if (flip === '' && actObj.flipObjColl.length > 1) {
1570
+ flip = actObj.flipObjColl[actObj.flipObjColl.length - 1];
1571
+ }
1572
+ if (actObj.flipObjColl.length <= 1) {
1573
+ var points = this.setTextBoxPos(actObj, degree, flip, x, y);
1574
+ x = points.x;
1575
+ y = points.y;
1576
+ }
1577
+ else {
1578
+ var points = this.setTextBoxPoints(actObj, degree, flip, x, y);
1579
+ x = points.x;
1580
+ y = points.y;
1581
+ }
1582
+ if (parent.activeObj.rotatedAngle !== 0) {
1583
+ x = parent.activeObj.horTopLinePointColl[0].x;
1584
+ y = parent.activeObj.horTopLinePointColl[0].y;
1585
+ }
1586
+ this.renderTextArea(x, y, actObj);
1587
+ }
1588
+ else {
1589
+ this.applyActObj();
1590
+ }
1591
+ }
1592
+ }
1593
+ else if (parent.textArea.style.display === 'block' && this.selectedText() !== '' && e.type === 'mousedown') {
1594
+ var temp = parent.textArea.value;
1595
+ parent.textArea.value += 'a';
1596
+ parent.textArea.value = temp;
1597
+ }
1598
+ else if (parent.textArea.style.display === 'none') {
1599
+ parent.textArea.style.display = 'block';
1600
+ }
1601
+ };
1602
+ Shape.prototype.setTextBoxPos = function (actObj, degree, flip, x, y) {
1603
+ var point = { x: x, y: y };
1604
+ switch (degree) {
1605
+ case 0:
1606
+ if (flip.toLowerCase() === 'horizontal') {
1607
+ point.x = actObj.activePoint.endX;
1608
+ point.y = actObj.activePoint.startY;
1609
+ }
1610
+ else if (flip.toLowerCase() === 'vertical') {
1611
+ point.x = actObj.activePoint.startX;
1612
+ point.y = actObj.activePoint.endY;
1613
+ }
1614
+ else {
1615
+ point.x = actObj.activePoint.startX;
1616
+ point.y = actObj.activePoint.startY;
1617
+ }
1618
+ break;
1619
+ case 90:
1620
+ if (flip.toLowerCase() === 'horizontal') {
1621
+ point.x = actObj.activePoint.startX;
1622
+ point.y = actObj.activePoint.startY;
1623
+ }
1624
+ else if (flip.toLowerCase() === 'vertical') {
1625
+ point.x = actObj.activePoint.endX;
1626
+ point.y = actObj.activePoint.endY;
1627
+ }
1628
+ else {
1629
+ point.x = actObj.activePoint.endX;
1630
+ point.y = actObj.activePoint.startY;
1631
+ }
1632
+ break;
1633
+ case 180:
1634
+ if (flip.toLowerCase() === 'horizontal') {
1635
+ point.x = actObj.activePoint.startX;
1636
+ point.y = actObj.activePoint.endY;
1637
+ }
1638
+ else if (flip.toLowerCase() === 'vertical') {
1639
+ point.x = actObj.activePoint.endX;
1640
+ point.y = actObj.activePoint.startY;
1641
+ }
1642
+ else {
1643
+ point.x = actObj.activePoint.endX;
1644
+ point.y = actObj.activePoint.endY;
1645
+ }
1646
+ break;
1647
+ case 270:
1648
+ if (flip.toLowerCase() === 'horizontal') {
1649
+ point.x = actObj.activePoint.endX;
1650
+ point.y = actObj.activePoint.endY;
1651
+ }
1652
+ else if (flip.toLowerCase() === 'vertical') {
1653
+ point.x = actObj.activePoint.startX;
1654
+ point.y = actObj.activePoint.startY;
1655
+ }
1656
+ else {
1657
+ point.x = actObj.activePoint.startX;
1658
+ point.y = actObj.activePoint.endY;
1659
+ }
1660
+ break;
1661
+ }
1662
+ return point;
1663
+ };
1664
+ Shape.prototype.setTextBoxPoints = function (actObj, degree, flip, x, y) {
1665
+ var point = { x: x, y: y };
1666
+ switch (degree) {
1667
+ case 0:
1668
+ if (actObj.flipObjColl[0] && actObj.flipObjColl[0].toLowerCase() === 'horizontal') {
1669
+ if (flip.toLowerCase() === 'horizontal') {
1670
+ point.x = (actObj.activePoint.startX);
1671
+ point.y = (actObj.activePoint.startY);
1672
+ }
1673
+ else if (flip.toLowerCase() === 'vertical') {
1674
+ point.x = (actObj.activePoint.endX);
1675
+ point.y = (actObj.activePoint.endY);
1676
+ }
1677
+ }
1678
+ else {
1679
+ if (flip.toLowerCase() === 'horizontal') {
1680
+ point.x = (actObj.activePoint.endX);
1681
+ point.y = (actObj.activePoint.endY);
1682
+ }
1683
+ else if (flip.toLowerCase() === 'vertical') {
1684
+ point.x = (actObj.activePoint.endX);
1685
+ point.y = (actObj.activePoint.startY);
1686
+ }
1687
+ }
1688
+ break;
1689
+ case 90:
1690
+ if (actObj.flipObjColl[0] && actObj.flipObjColl[0].toLowerCase() === 'horizontal') {
1691
+ if (flip.toLowerCase() === 'horizontal') {
1692
+ point.x = (actObj.activePoint.endX);
1693
+ point.y = (actObj.activePoint.endY);
1694
+ }
1695
+ else if (flip.toLowerCase() === 'vertical') {
1696
+ point.x = (actObj.activePoint.startX);
1697
+ point.y = (actObj.activePoint.endY);
1698
+ }
1699
+ }
1700
+ else {
1701
+ if (flip.toLowerCase() === 'horizontal') {
1702
+ point.x = (actObj.activePoint.startX);
1703
+ point.y = (actObj.activePoint.endY);
1704
+ }
1705
+ else if (flip.toLowerCase() === 'vertical') {
1706
+ point.x = (actObj.activePoint.startX);
1707
+ point.y = (actObj.activePoint.startY);
1708
+ }
1709
+ }
1710
+ break;
1711
+ case 180:
1712
+ if (actObj.flipObjColl[0] && actObj.flipObjColl[0].toLowerCase() === 'horizontal') {
1713
+ if (flip.toLowerCase() === 'horizontal') {
1714
+ point.x = (actObj.activePoint.startX);
1715
+ point.y = (actObj.activePoint.startY);
1716
+ }
1717
+ else if (flip.toLowerCase() === 'vertical') {
1718
+ point.x = (actObj.activePoint.startX);
1719
+ point.y = (actObj.activePoint.startY);
1720
+ }
1721
+ }
1722
+ else {
1723
+ if (flip.toLowerCase() === 'horizontal') {
1724
+ point.x = (actObj.activePoint.startX);
1725
+ point.y = (actObj.activePoint.startY);
1726
+ }
1727
+ else if (flip.toLowerCase() === 'vertical') {
1728
+ point.x = (actObj.activePoint.startX);
1729
+ point.y = (actObj.activePoint.endY);
1730
+ }
1731
+ }
1732
+ break;
1733
+ case 270:
1734
+ if (actObj.flipObjColl[0] && actObj.flipObjColl[0].toLowerCase() === 'horizontal') {
1735
+ if (flip.toLowerCase() === 'horizontal') {
1736
+ point.x = (actObj.activePoint.startX);
1737
+ point.y = (actObj.activePoint.startY);
1738
+ }
1739
+ else if (flip.toLowerCase() === 'vertical') {
1740
+ point.x = (actObj.activePoint.endX);
1741
+ point.y = (actObj.activePoint.startY);
1742
+ }
1743
+ }
1744
+ else {
1745
+ if (flip.toLowerCase() === 'horizontal') {
1746
+ point.x = (actObj.activePoint.endX);
1747
+ point.y = (actObj.activePoint.startY);
1748
+ }
1749
+ else if (flip.toLowerCase() === 'vertical') {
1750
+ point.x = (actObj.activePoint.endX);
1751
+ point.y = (actObj.activePoint.endY);
1752
+ }
1753
+ }
1754
+ break;
1755
+ }
1756
+ return point;
1757
+ };
1758
+ Shape.prototype.selectedText = function () {
1759
+ var start = this.parent.textArea.selectionStart;
1760
+ var finish = this.parent.textArea.selectionEnd;
1761
+ return this.parent.textArea.value.substring(start, finish);
1762
+ };
1763
+ Shape.prototype.panObjColl = function (xDiff, yDiff, panRegion) {
1764
+ var parent = this.parent;
1765
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
1766
+ var currObj = parent.objColl[i];
1767
+ if (panRegion === '' || panRegion === 'vertical') {
1768
+ currObj.activePoint.startX += xDiff;
1769
+ currObj.activePoint.endX += xDiff;
1770
+ if (currObj.rotationCirclePointColl) {
1771
+ currObj.rotationCirclePointColl.x += xDiff;
1772
+ }
1773
+ if (currObj.shape === 'path') {
1774
+ for (var l = 0, len_3 = currObj.pointColl.length; l < len_3; l++) {
1775
+ currObj.pointColl[l].x += xDiff;
1776
+ }
1777
+ }
1778
+ }
1779
+ else {
1780
+ currObj.activePoint.startX -= xDiff;
1781
+ currObj.activePoint.endX -= xDiff;
1782
+ if (currObj.rotationCirclePointColl) {
1783
+ currObj.rotationCirclePointColl.x -= xDiff;
1784
+ }
1785
+ if (currObj.shape === 'path') {
1786
+ for (var l = 0, len_4 = currObj.pointColl.length; l < len_4; l++) {
1787
+ currObj.pointColl[l].x -= xDiff;
1788
+ }
1789
+ }
1790
+ }
1791
+ if (panRegion === '' || panRegion === 'horizontal') {
1792
+ currObj.activePoint.startY += yDiff;
1793
+ currObj.activePoint.endY += yDiff;
1794
+ if (currObj.rotationCirclePointColl) {
1795
+ currObj.rotationCirclePointColl.y += yDiff;
1796
+ }
1797
+ if (currObj.shape === 'path') {
1798
+ for (var l = 0; l < currObj.pointColl.length; l++) {
1799
+ currObj.pointColl[l].y += yDiff;
1800
+ }
1801
+ }
1802
+ }
1803
+ else {
1804
+ currObj.activePoint.startY -= yDiff;
1805
+ currObj.activePoint.endY -= yDiff;
1806
+ if (currObj.rotationCirclePointColl) {
1807
+ currObj.rotationCirclePointColl.y -= yDiff;
1808
+ }
1809
+ if (currObj.shape === 'path') {
1810
+ for (var l = 0; l < currObj.pointColl.length; l++) {
1811
+ currObj.pointColl[l].y -= yDiff;
1812
+ }
1813
+ }
1814
+ }
1815
+ currObj = this.updateWidthHeight(currObj);
1816
+ parent.notify('draw', { prop: 'updateActiveObject', onPropertyChange: false, value: { actPoint: currObj.activePoint,
1817
+ obj: currObj } });
1818
+ if (currObj.shape === 'line' || currObj.shape === 'arrow') {
1819
+ currObj.pointColl = this.getLinePoints(currObj.activePoint.startX, currObj.activePoint.startY, currObj.activePoint.endX, currObj.activePoint.endY);
1820
+ for (var j = 0, len_5 = currObj.pointColl.length; j < len_5; j++) {
1821
+ currObj.pointColl[j].ratioX =
1822
+ (currObj.pointColl[j].x - parent.img.destLeft) / parent.img.destWidth;
1823
+ currObj.pointColl[j].ratioY =
1824
+ (currObj.pointColl[j].y - parent.img.destTop) / parent.img.destHeight;
1825
+ }
1826
+ }
1827
+ var temp = this.lowerContext.filter;
1828
+ this.lowerContext.filter = 'none';
1829
+ this.apply(currObj.shape, currObj);
1830
+ this.lowerContext.filter = temp;
1831
+ this.refreshActiveObj();
1832
+ }
1833
+ };
1834
+ Shape.prototype.updateFontStyles = function (isTextBox) {
1835
+ var parent = this.parent;
1836
+ this.upperContext.strokeStyle = parent.activeObj.strokeSettings.strokeColor;
1837
+ this.upperContext.fillStyle = parent.activeObj.strokeSettings.strokeColor;
1838
+ var textStyle = '';
1839
+ if (parent.activeObj.textSettings.bold) {
1840
+ textStyle = 'bold ';
1841
+ }
1842
+ if (parent.activeObj.textSettings.italic) {
1843
+ textStyle = 'italic ';
1844
+ }
1845
+ if (parent.activeObj.textSettings.bold && parent.activeObj.textSettings.italic) {
1846
+ textStyle = 'italic bold ';
1847
+ }
1848
+ var fontSize = isTextBox ? parseFloat(parent.textArea.style.fontSize) : parent.activeObj.textSettings.fontSize;
1849
+ var fontFamily = parent.textArea.style.display === 'block' ? parent.textArea.style.fontFamily : parent.activeObj.textSettings.fontFamily;
1850
+ this.upperContext.font = textStyle + fontSize + 'px' + ' ' + fontFamily;
1851
+ };
1852
+ Shape.prototype.applyFontStyle = function (item) {
1853
+ var parent = this.parent;
1854
+ this.pushActItemIntoObj();
1855
+ var objColl = extend([], parent.objColl, [], true);
1856
+ parent.objColl.pop();
1857
+ if (parent.textArea.style.display === 'none') {
1858
+ this.updateFontRatio(parent.activeObj);
1859
+ }
1860
+ else {
1861
+ this.updateFontRatio(parent.activeObj, true);
1862
+ }
1863
+ switch (item) {
1864
+ case 'default':
1865
+ this.updateFontStyle(item, objColl, 'normal', 'normal');
1866
+ break;
1867
+ case 'bold':
1868
+ this.updateFontStyle(item, objColl, 'bold', 'normal');
1869
+ break;
1870
+ case 'italic':
1871
+ this.updateFontStyle(item, objColl, 'normal', 'italic');
1872
+ break;
1873
+ case 'bolditalic':
1874
+ this.updateFontStyle(item, objColl, 'bold', 'italic');
1875
+ break;
1876
+ }
1877
+ };
1878
+ Shape.prototype.updateFontStyle = function (item, objColl, fontWeight, fontStyle) {
1879
+ var parent = this.parent;
1880
+ if (parent.textArea.style.display === 'block') {
1881
+ var width = this.getTextAreaWidth(item);
1882
+ parent.textArea.style.width = width + 'px';
1883
+ parent.textArea.style.fontWeight = fontWeight;
1884
+ parent.textArea.style.fontStyle = fontStyle;
1885
+ this.updateObjColl(item, objColl);
1886
+ }
1887
+ else {
1888
+ this.textSettings.bold = parent.activeObj.textSettings.bold = fontWeight === 'normal' ? false : true;
1889
+ this.textSettings.italic = parent.activeObj.textSettings.italic = fontStyle === 'normal' ? false : true;
1890
+ this.redrawText();
1891
+ parent.notify('undo-redo', { prop: 'updateUrObj', onPropertyChange: false, value: { objColl: objColl } });
1892
+ }
1893
+ };
1894
+ Shape.prototype.updateArrowRatio = function (obj) {
1895
+ var parent = this.parent;
1896
+ var object = { arrowDimension: null };
1897
+ parent.notify('draw', { prop: 'getArrowDimension', onPropertyChange: false, value: { obj: object } });
1898
+ var length;
1899
+ var degree = this.getRotDegOfShape(obj);
1900
+ if (degree === 0 || degree === 180 || degree === -180) {
1901
+ length = Math.abs(obj.activePoint.width);
1902
+ }
1903
+ else {
1904
+ length = Math.abs(obj.activePoint.height);
1905
+ }
1906
+ var dimension;
1907
+ var dimensions = ['bar', 'arrow', 'arrowSolid', 'circle', 'square'];
1908
+ for (var _i = 0, dimensions_1 = dimensions; _i < dimensions_1.length; _i++) {
1909
+ dimension = dimensions_1[_i];
1910
+ var ratioX = length / object['arrowDimension'][dimension]['width'];
1911
+ var ratioY = length / object['arrowDimension'][dimension]['height'];
1912
+ object['arrowDimension'][dimension]['ratioX'] = ratioX;
1913
+ object['arrowDimension'][dimension]['ratioY'] = ratioY;
1914
+ }
1915
+ };
1916
+ Shape.prototype.updateArrowSize = function (obj) {
1917
+ var object = { arrowDimension: null };
1918
+ this.parent.notify('draw', { prop: 'getArrowDimension', onPropertyChange: false, value: { obj: object } });
1919
+ var length;
1920
+ var degree = this.getRotDegOfShape(obj);
1921
+ if (degree === 0 || degree === 180 || degree === -180) {
1922
+ length = Math.abs(obj.activePoint.width);
1923
+ }
1924
+ else {
1925
+ length = Math.abs(obj.activePoint.height);
1926
+ }
1927
+ var dimension;
1928
+ var dimensions = ['bar', 'arrow', 'arrowSolid', 'circle', 'square'];
1929
+ for (var _i = 0, dimensions_2 = dimensions; _i < dimensions_2.length; _i++) {
1930
+ dimension = dimensions_2[_i];
1931
+ var ratioX = object['arrowDimension'][dimension]['ratioX'];
1932
+ var ratioY = object['arrowDimension'][dimension]['ratioY'];
1933
+ object['arrowDimension'][dimension]['width'] = length / ratioX;
1934
+ object['arrowDimension'][dimension]['height'] = length / ratioY;
1935
+ }
1936
+ };
1937
+ Shape.prototype.updateFontRatio = function (obj, isTextArea) {
1938
+ var parent = this.parent;
1939
+ var text = this.getMaxText(isTextArea);
1940
+ var width = this.upperContext.measureText(text).width +
1941
+ parent.activeObj.textSettings.fontSize * 0.5;
1942
+ var height = (parent.activeObj.textSettings.fontSize + parent.activeObj.textSettings.fontSize * 0.25);
1943
+ var degree = this.getRotDegOfShape(obj);
1944
+ if (isNullOrUndefined(isTextArea)) {
1945
+ if (degree === 0 || Math.abs(degree) === 180) {
1946
+ obj.textSettings.fontRatio = width / obj.textSettings.fontSize;
1947
+ }
1948
+ else {
1949
+ obj.textSettings.fontRatio = height / obj.textSettings.fontSize;
1950
+ }
1951
+ }
1952
+ else if (isTextArea) {
1953
+ obj.textSettings.fontRatio = width / parseFloat(parent.textArea.style.fontSize);
1954
+ }
1955
+ };
1956
+ Shape.prototype.updateFontSize = function (obj) {
1957
+ var degree = this.getRotDegOfShape(obj);
1958
+ if (degree === 0 || Math.abs(degree) === 180) {
1959
+ obj.textSettings.fontSize = (obj.activePoint.width / obj.textSettings.fontRatio);
1960
+ }
1961
+ else {
1962
+ obj.textSettings.fontSize = (obj.activePoint.height / obj.textSettings.fontRatio);
1963
+ }
1964
+ };
1965
+ Shape.prototype.updateObjColl = function (item, objColl) {
1966
+ var parent = this.parent;
1967
+ var prevCropObj = extend({}, parent.cropObj, {}, true);
1968
+ var object = { currObj: {} };
1969
+ parent.notify('filter', { prop: 'getCurrentObj', onPropertyChange: false, value: { object: object } });
1970
+ var prevObj = object['currObj'];
1971
+ prevObj.objColl = objColl;
1972
+ prevObj.pointColl = extend([], parent.pointColl, [], true);
1973
+ prevObj.afterCropActions = extend([], parent.afterCropActions, [], true);
1974
+ var selPointCollObj = { selPointColl: null };
1975
+ parent.notify('freehand-draw', { prop: 'getSelPointColl', onPropertyChange: false,
1976
+ value: { obj: selPointCollObj } });
1977
+ prevObj.selPointColl = extend([], selPointCollObj['selPointColl'], [], true);
1978
+ var tempBold = parent.activeObj.textSettings.bold;
1979
+ var tempItalic = parent.activeObj.textSettings.italic;
1980
+ switch (item) {
1981
+ case 'default':
1982
+ parent.activeObj.textSettings.bold = false;
1983
+ parent.activeObj.textSettings.italic = false;
1984
+ break;
1985
+ case 'bold':
1986
+ parent.activeObj.textSettings.bold = true;
1987
+ parent.activeObj.textSettings.italic = false;
1988
+ break;
1989
+ case 'italic':
1990
+ parent.activeObj.textSettings.bold = false;
1991
+ parent.activeObj.textSettings.italic = true;
1992
+ break;
1993
+ case 'bolditalic':
1994
+ parent.activeObj.textSettings.bold = true;
1995
+ parent.activeObj.textSettings.italic = true;
1996
+ break;
1997
+ }
1998
+ parent.objColl.push(parent.activeObj);
1999
+ parent.notify('undo-redo', { prop: 'updateUndoRedoColl', onPropertyChange: false,
2000
+ value: { operation: 'textAreaCustomization', previousObj: prevObj, previousObjColl: prevObj.objColl,
2001
+ previousPointColl: prevObj.pointColl, previousSelPointColl: prevObj.selPointColl,
2002
+ previousCropObj: prevCropObj, previousText: null,
2003
+ currentText: null, previousFilter: null, isCircleCrop: null } });
2004
+ parent.objColl.pop();
2005
+ parent.activeObj.textSettings.bold = tempBold;
2006
+ parent.activeObj.textSettings.italic = tempItalic;
2007
+ };
2008
+ Shape.prototype.pushActItemIntoObj = function () {
2009
+ if (this.parent.textArea.style.display === 'none') {
2010
+ this.parent.objColl.push(this.parent.activeObj);
2011
+ }
2012
+ else {
2013
+ var temp = extend({}, this.parent.activeObj, {}, true);
2014
+ this.parent.notify('selection', { prop: 'setTextBoxStylesToActObj', onPropertyChange: false });
2015
+ this.parent.objColl.push(this.parent.activeObj);
2016
+ this.parent.activeObj = temp;
2017
+ }
2018
+ };
2019
+ Shape.prototype.clearActObj = function () {
2020
+ if (this.parent.textArea.style.display === 'none') {
2021
+ this.refreshActiveObj();
2022
+ this.applyActObj();
2023
+ this.refreshActiveObj();
2024
+ this.parent.currObjType.isCustomCrop = false;
2025
+ }
2026
+ };
2027
+ Shape.prototype.refreshActiveObj = function () {
2028
+ this.parent.activeObj = {};
2029
+ this.parent.activeObj.activePoint = { startX: 0, startY: 0, endX: 0, endY: 0, width: 0, height: 0 };
2030
+ this.parent.activeObj.triangle = [];
2031
+ this.parent.activeObj.triangleRatio = [];
2032
+ this.parent.activeObj.flipObjColl = [];
2033
+ this.parent.activeObj.strokeSettings = this.strokeSettings;
2034
+ this.parent.activeObj.textSettings = this.textSettings;
2035
+ this.parent.activeObj.rotatedAngle = 0;
2036
+ };
2037
+ Shape.prototype.applyActObj = function (isMouseDown) {
2038
+ var isActObj = false;
2039
+ if (this.parent.activeObj.shape !== undefined && this.parent.activeObj.shape === 'text' && this.parent.activeObj.keyHistory === '') {
2040
+ this.refreshActiveObj();
2041
+ this.upperContext.clearRect(0, 0, this.parent.upperCanvas.width, this.parent.upperCanvas.height);
2042
+ }
2043
+ else {
2044
+ var splitWords = void 0;
2045
+ var isCropSelection = false;
2046
+ if (this.parent.activeObj.shape !== undefined) {
2047
+ splitWords = this.parent.activeObj.shape.split('-');
2048
+ }
2049
+ if (splitWords === undefined && this.parent.currObjType.isCustomCrop) {
2050
+ isCropSelection = true;
2051
+ }
2052
+ else if (splitWords !== undefined && splitWords[0] === 'crop') {
2053
+ isCropSelection = true;
2054
+ }
2055
+ if (this.parent.activeObj.shape && !isCropSelection && this.parent.activeObj.shape !== 'shape') {
2056
+ for (var i = 0; i < this.parent.objColl.length; i++) {
2057
+ if (JSON.stringify(this.parent.activeObj) === JSON.stringify(this.parent.objColl[i])) {
2058
+ isActObj = true;
2059
+ break;
2060
+ }
2061
+ }
2062
+ if (!isActObj) {
2063
+ if (isNullOrUndefined(this.parent.activeObj.currIndex)) {
2064
+ this.parent.activeObj.currIndex = 'shape_' + (this.parent.objColl.length + 1);
2065
+ }
2066
+ this.updImgRatioForActObj();
2067
+ var splitWords_1 = this.parent.activeObj.currIndex.split('_');
2068
+ var tempObjColl = this.parent.objColl.splice(0, parseInt(splitWords_1[1], 10) - 1);
2069
+ tempObjColl.push(extend({}, this.parent.activeObj, {}, true));
2070
+ for (var i = 0; i < this.parent.objColl.length; i++) {
2071
+ tempObjColl.push(this.parent.objColl[i]);
2072
+ }
2073
+ this.parent.objColl = tempObjColl;
2074
+ tempObjColl = [];
2075
+ this.refreshActiveObj();
2076
+ this.lowerContext.clearRect(0, 0, this.parent.lowerCanvas.width, this.parent.lowerCanvas.height);
2077
+ this.parent.notify('draw', { prop: 'redrawImgWithObj', onPropertyChange: false });
2078
+ this.parent.notify('draw', { prop: 'clearOuterCanvas', onPropertyChange: false, value: { context: this.lowerContext } });
2079
+ this.parent.notify('draw', { prop: 'clearOuterCanvas', onPropertyChange: false, value: { context: this.upperContext } });
2080
+ this.parent.currObjType.shape = '';
2081
+ this.refreshActiveObj();
2082
+ if (this.parent.isCircleCrop) {
2083
+ this.parent.notify('crop', { prop: 'cropCircle', onPropertyChange: false,
2084
+ value: { context: this.lowerContext, isSave: null, isFlip: null } });
2085
+ }
2086
+ if (!isBlazor()) {
2087
+ this.parent.notify('toolbar', { prop: 'destroy-qa-toolbar', onPropertyChange: false });
2088
+ }
2089
+ else {
2090
+ this.parent.updateToolbar(this.parent.element, 'destroyQuickAccessToolbar');
2091
+ }
2092
+ if (isNullOrUndefined(isMouseDown)) {
2093
+ this.parent.notify('undo-redo', { prop: 'updateCurrUrc', value: { type: 'ok' } });
2094
+ this.parent.notify('draw', { prop: 'setPrevActObj', onPropertyChange: false, value: { prevActObj: null } });
2095
+ }
2096
+ }
2097
+ }
2098
+ }
2099
+ };
2100
+ Shape.prototype.alignTextAreaIntoCanvas = function () {
2101
+ var parent = this.parent;
2102
+ var letters = parent.textArea.value;
2103
+ parent.textArea.value = '';
2104
+ for (var i = 0, len = letters.length; i < len; i++) {
2105
+ parent.textArea.value += letters[i];
2106
+ parent.textArea.style.height = 'auto';
2107
+ parent.textArea.style.height = parent.textArea.scrollHeight + 'px';
2108
+ this.setTextBoxWidth();
2109
+ }
2110
+ };
2111
+ Shape.prototype.transformTextArea = function () {
2112
+ var parent = this.parent;
2113
+ if (parent.activeObj.shape === 'text') {
2114
+ parent.textArea.style.transformOrigin = '0 0';
2115
+ var rotatedDegree = parent.activeObj.rotatedAngle * (180 / Math.PI);
2116
+ var scale = '';
2117
+ var degree = this.getRotDegOfShape(parent.activeObj);
2118
+ if (parent.activeObj.flipObjColl.length > 0) {
2119
+ // need to add scale value according to length.
2120
+ for (var i = 0; i < parent.activeObj.flipObjColl.length; i++) {
2121
+ if (degree !== 0 && degree % 90 === 0 && degree !== 180) {
2122
+ scale += parent.activeObj.flipObjColl[i].toLowerCase() === 'horizontal' ? 'scale(1, -1)' :
2123
+ 'scale(-1, 1)';
2124
+ }
2125
+ else {
2126
+ scale += parent.activeObj.flipObjColl[i].toLowerCase() === 'horizontal' ? 'scale(-1, 1)' :
2127
+ 'scale(1, -1)';
2128
+ }
2129
+ degree += rotatedDegree;
2130
+ if (parent.activeObj.flipObjColl[i].toLowerCase() === 'horizontal') {
2131
+ parent.textArea.style.transform = 'rotate(' + degree + 'deg)' + scale;
2132
+ }
2133
+ else if (parent.activeObj.flipObjColl[i].toLowerCase() === 'vertical') {
2134
+ parent.textArea.style.transform = 'rotate(' + degree + 'deg)' + scale;
2135
+ }
2136
+ }
2137
+ }
2138
+ else {
2139
+ degree += rotatedDegree;
2140
+ parent.textArea.style.transform = 'rotate(' + degree + 'deg)';
2141
+ }
2142
+ }
2143
+ };
2144
+ Shape.prototype.getTextAreaWidth = function (item) {
2145
+ var parent = this.parent;
2146
+ var tempBold = parent.activeObj.textSettings.bold;
2147
+ var tempItalic = parent.activeObj.textSettings.italic;
2148
+ switch (item) {
2149
+ case 'default':
2150
+ parent.activeObj.textSettings.bold = false;
2151
+ parent.activeObj.textSettings.italic = false;
2152
+ break;
2153
+ case 'bold':
2154
+ parent.activeObj.textSettings.bold = true;
2155
+ parent.activeObj.textSettings.italic = false;
2156
+ break;
2157
+ case 'italic':
2158
+ parent.activeObj.textSettings.bold = false;
2159
+ parent.activeObj.textSettings.italic = true;
2160
+ break;
2161
+ case 'bolditalic':
2162
+ parent.activeObj.textSettings.bold = true;
2163
+ parent.activeObj.textSettings.italic = true;
2164
+ break;
2165
+ }
2166
+ this.updateFontStyles();
2167
+ var width;
2168
+ if (parent.textArea.style.display === 'none') {
2169
+ width = this.upperContext.measureText(parent.activeObj.keyHistory).width +
2170
+ parent.activeObj.textSettings.fontSize * 0.5;
2171
+ }
2172
+ else {
2173
+ width = this.upperContext.measureText(parent.textArea.value).width +
2174
+ parent.activeObj.textSettings.fontSize * 0.5;
2175
+ }
2176
+ parent.activeObj.textSettings.bold = tempBold;
2177
+ parent.activeObj.textSettings.italic = tempItalic;
2178
+ return width;
2179
+ };
2180
+ Shape.prototype.getObjDetails = function (obj) {
2181
+ var parent = this.parent;
2182
+ var shapeDetails = {};
2183
+ shapeDetails.id = obj.currIndex;
2184
+ shapeDetails.type = parent.toPascalCase(obj.shape);
2185
+ shapeDetails.startX = obj.activePoint.startX;
2186
+ shapeDetails.startY = obj.activePoint.startY;
2187
+ switch (obj.shape) {
2188
+ case 'rectangle':
2189
+ shapeDetails.width = obj.activePoint.width;
2190
+ shapeDetails.height = obj.activePoint.height;
2191
+ shapeDetails.strokeColor = obj.strokeSettings.strokeColor;
2192
+ shapeDetails.fillColor = obj.strokeSettings.fillColor;
2193
+ shapeDetails.strokeWidth = obj.strokeSettings.strokeWidth;
2194
+ break;
2195
+ case 'ellipse':
2196
+ shapeDetails.radius = obj.activePoint.width / 2;
2197
+ shapeDetails.strokeColor = obj.strokeSettings.strokeColor;
2198
+ shapeDetails.fillColor = obj.strokeSettings.fillColor;
2199
+ shapeDetails.strokeWidth = obj.strokeSettings.strokeWidth;
2200
+ break;
2201
+ case 'line':
2202
+ case 'arrow':
2203
+ shapeDetails.length = obj.activePoint.width;
2204
+ shapeDetails.strokeColor = obj.strokeSettings.strokeColor;
2205
+ shapeDetails.strokeWidth = obj.strokeSettings.strokeWidth;
2206
+ break;
2207
+ case 'text':
2208
+ shapeDetails.text = obj.keyHistory;
2209
+ shapeDetails.fontSize = obj.textSettings.fontSize;
2210
+ shapeDetails.color = obj.strokeSettings.strokeColor;
2211
+ shapeDetails.fontStyle = [];
2212
+ if (obj.textSettings.bold) {
2213
+ shapeDetails.fontStyle.push('bold');
2214
+ }
2215
+ if (obj.textSettings.italic) {
2216
+ shapeDetails.fontStyle.push('italic');
2217
+ }
2218
+ break;
2219
+ }
2220
+ return shapeDetails;
2221
+ };
2222
+ Shape.prototype.getFreehandDrawDetails = function (index) {
2223
+ var parent = this.parent;
2224
+ var shapeDetails = {};
2225
+ shapeDetails.id = parent.pointColl[index].id;
2226
+ shapeDetails.type = ShapeType.FreehandDraw;
2227
+ shapeDetails.points = extend([], parent.pointColl[index].points);
2228
+ shapeDetails.strokeColor = parent.pointColl[index].strokeColor;
2229
+ shapeDetails.strokeWidth = parent.pointColl[index].strokeWidth;
2230
+ return shapeDetails;
2231
+ };
2232
+ Shape.prototype.getShapeSetting = function (id, obj) {
2233
+ var parent = this.parent;
2234
+ var shapeDetails;
2235
+ if (!parent.disabled && parent.isImageLoaded) {
2236
+ this.applyActObj();
2237
+ if (id.split('_')[0] === 'shape') {
2238
+ var obj_1;
2239
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
2240
+ if (parent.objColl[i].currIndex === id) {
2241
+ obj_1 = extend({}, parent.objColl[i], {}, true);
2242
+ break;
2243
+ }
2244
+ }
2245
+ shapeDetails = this.getObjDetails(obj_1);
2246
+ }
2247
+ else if (id.split('_')[0] === 'pen') {
2248
+ shapeDetails = this.getFreehandDrawDetails(parseInt(id.split('_')[1], 10) - 1);
2249
+ }
2250
+ }
2251
+ obj['shapeDetails'] = shapeDetails;
2252
+ };
2253
+ Shape.prototype.getShapeSettings = function (obj) {
2254
+ var parent = this.parent;
2255
+ var shapeDetailsColl = [];
2256
+ if (!parent.disabled && parent.isImageLoaded) {
2257
+ this.applyActObj();
2258
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
2259
+ var shapeDetails = this.getObjDetails(parent.objColl[i]);
2260
+ shapeDetailsColl.push(shapeDetails);
2261
+ }
2262
+ for (var i = 0; i < parent.freehandCounter; i++) {
2263
+ var shapeDetails = this.getFreehandDrawDetails(i);
2264
+ shapeDetailsColl.push(shapeDetails);
2265
+ }
2266
+ }
2267
+ obj['shapeDetailsColl'] = shapeDetailsColl;
2268
+ };
2269
+ Shape.prototype.isPointsInRange = function (x, y, obj) {
2270
+ var inRange = false;
2271
+ if (!isNullOrUndefined(x) && !isNullOrUndefined(y) && x >= this.parent.img.destLeft && y >= this.parent.img.destTop &&
2272
+ x <= this.parent.img.destLeft + this.parent.img.destWidth && y <= this.parent.img.destTop + this.parent.img.destHeight) {
2273
+ inRange = true;
2274
+ }
2275
+ obj['inRange'] = inRange;
2276
+ };
2277
+ Shape.prototype.alignRotateFlipColl = function (collection, isRotateFlipCollection, obj) {
2278
+ collection = this.popForDefaultTransformedState(collection);
2279
+ collection = this.popForDefaultFlipState(collection);
2280
+ collection = this.popForDefaultRotateState(collection);
2281
+ if (collection.length === 0 && isRotateFlipCollection) {
2282
+ this.parent.transform.degree = 0;
2283
+ this.parent.transform.currFlipState = '';
2284
+ }
2285
+ obj['collection'] = collection;
2286
+ return collection;
2287
+ };
2288
+ Shape.prototype.popForDefaultTransformedState = function (collection) {
2289
+ var rotateRight = 0;
2290
+ var rotateleft = 0;
2291
+ var horizontal = 0;
2292
+ var vertical = 0;
2293
+ for (var i = 0; i < collection.length; i++) {
2294
+ if (collection[i] === 90 || collection[i] === 'rotateRight') {
2295
+ rotateRight++;
2296
+ rotateleft = 0;
2297
+ horizontal = 0;
2298
+ vertical = 0;
2299
+ if (rotateRight === 4) {
2300
+ collection.pop();
2301
+ collection.pop();
2302
+ collection.pop();
2303
+ collection.pop();
2304
+ }
2305
+ }
2306
+ else if (collection[i] === -90 || collection[i] === 'rotateLeft') {
2307
+ rotateleft++;
2308
+ rotateRight = 0;
2309
+ horizontal = 0;
2310
+ vertical = 0;
2311
+ if (rotateleft === 4) {
2312
+ collection.pop();
2313
+ collection.pop();
2314
+ collection.pop();
2315
+ collection.pop();
2316
+ }
2317
+ }
2318
+ else if (collection[i] === 'horizontal' || collection[i] === 'Horizontal'
2319
+ || collection[i] === 'horizontalflip') {
2320
+ horizontal++;
2321
+ rotateleft = 0;
2322
+ rotateRight = 0;
2323
+ vertical = 0;
2324
+ if (horizontal === 2) {
2325
+ collection.pop();
2326
+ collection.pop();
2327
+ }
2328
+ }
2329
+ else if (collection[i] === 'vertical' || collection[i] === 'Vertical'
2330
+ || collection[i] === 'verticalflip') {
2331
+ vertical++;
2332
+ horizontal = 0;
2333
+ rotateleft = 0;
2334
+ rotateRight = 0;
2335
+ if (vertical === 2) {
2336
+ collection.pop();
2337
+ collection.pop();
2338
+ }
2339
+ }
2340
+ }
2341
+ return collection;
2342
+ };
2343
+ Shape.prototype.popForDefaultFlipState = function (collection) {
2344
+ for (var i = 0; i < collection.length; i++) {
2345
+ if (!isNullOrUndefined(collection[i + 3])) {
2346
+ if ((collection[i] === 'horizontal' || collection[i] === 'Horizontal'
2347
+ || collection[i] === 'horizontalFlip')
2348
+ && (collection[i + 1] === 'vertical' || collection[i + 1] === 'Vertical'
2349
+ || collection[i] === 'verticalFlip') &&
2350
+ (collection[i + 2] === 'horizontal' || collection[i + 2] === 'Horizontal'
2351
+ || collection[i] === 'horizontalFlip') &&
2352
+ (collection[i + 3] === 'vertical' || collection[i + 3] === 'Vertical'
2353
+ || collection[i] === 'verticalFlip')) {
2354
+ collection.pop();
2355
+ collection.pop();
2356
+ collection.pop();
2357
+ collection.pop();
2358
+ }
2359
+ else if ((collection[i] === 'vertical' || collection[i] === 'Vertical'
2360
+ || collection[i] === 'verticalFlip')
2361
+ && (collection[i + 1] === 'horizontal' || collection[i + 1] === 'Horizontal'
2362
+ || collection[i + 1] === 'horizontalFlip') &&
2363
+ (collection[i + 2] === 'vertical' || collection[i + 2] === 'Vertical' || collection[i] === 'verticalFlip') &&
2364
+ (collection[i + 3] === 'horizontal' || collection[i + 3] === 'Horizontal' || collection[i] === 'horizontalFlip')) {
2365
+ collection.pop();
2366
+ collection.pop();
2367
+ collection.pop();
2368
+ collection.pop();
2369
+ }
2370
+ }
2371
+ }
2372
+ return collection;
2373
+ };
2374
+ Shape.prototype.popForDefaultRotateState = function (collection) {
2375
+ for (var i = 0; i < collection.length; i++) {
2376
+ if (!isNullOrUndefined(collection[i + 1])) {
2377
+ if ((collection[i] === 90 || collection[i] === 'rotateRight') &&
2378
+ (collection[i + 1] === -90 || collection[i] === 'rotateLeft')) {
2379
+ collection.pop();
2380
+ collection.pop();
2381
+ }
2382
+ else if ((collection[i] === -90 || collection[i] === 'rotateLeft') &&
2383
+ (collection[i + 1] === 90 || collection[i] === 'rotateRight')) {
2384
+ collection.pop();
2385
+ collection.pop();
2386
+ }
2387
+ }
2388
+ }
2389
+ return collection;
2390
+ };
2391
+ Shape.prototype.selectShape = function (id, obj) {
2392
+ var parent = this.parent;
2393
+ var isSelected = false;
2394
+ if (!parent.disabled && parent.isImageLoaded) {
2395
+ this.applyActObj();
2396
+ if (id.split('_')[0] === 'shape') {
2397
+ var obj_2;
2398
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
2399
+ if (parent.objColl[i].currIndex === id) {
2400
+ obj_2 = extend({}, parent.objColl[i], {}, true);
2401
+ break;
2402
+ }
2403
+ }
2404
+ if (isNullOrUndefined(obj_2)) {
2405
+ isSelected = false;
2406
+ }
2407
+ else {
2408
+ isSelected = true;
2409
+ parent.activeObj = obj_2;
2410
+ var object = { canvasFilter: null };
2411
+ parent.notify('toolbar', { prop: 'getCanvasFilter', onPropertyChange: false, value: { obj: object } });
2412
+ this.lowerContext.filter = object['canvasFilter'];
2413
+ parent.notify('selection', { prop: 'redrawShape', onPropertyChange: false,
2414
+ value: { obj: parent.activeObj } });
2415
+ if (!isBlazor()) {
2416
+ if (parent.activeObj.shape === 'text') {
2417
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: { type: 'text',
2418
+ isApplyBtn: null, isCropping: null, isZooming: null, cType: null } });
2419
+ }
2420
+ else if (parent.activeObj.shape === 'pen') {
2421
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: { type: 'pen',
2422
+ isApplyBtn: null, isCropping: null, isZooming: null, cType: null } });
2423
+ }
2424
+ else {
2425
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: { type: 'shapes',
2426
+ isApplyBtn: null, isCropping: null, isZooming: null, cType: null } });
2427
+ }
2428
+ parent.notify('toolbar', { prop: 'update-toolbar-items', onPropertyChange: false });
2429
+ parent.notify('toolbar', { prop: 'renderQAT', onPropertyChange: false, value: { isPenEdit: null } });
2430
+ }
2431
+ else {
2432
+ parent.updateToolbar(parent.element, parent.activeObj.shape);
2433
+ if (parent.activeObj.shape === 'path') {
2434
+ parent.updateToolbar(this.parent.element, 'path', 'pathQuickAccessToolbar');
2435
+ }
2436
+ else {
2437
+ parent.updateToolbar(parent.element, 'quickAccessToolbar', parent.activeObj.shape);
2438
+ }
2439
+ }
2440
+ }
2441
+ }
2442
+ else if (id.split('_')[0] === 'pen') {
2443
+ var object = { bool: false };
2444
+ parent.notify('selection', { prop: 'getFreehandDrawEditing', onPropertyChange: false, value: { obj: object } });
2445
+ if (object['bool']) {
2446
+ parent.okBtn();
2447
+ }
2448
+ var obj_3 = { isIndex: false };
2449
+ parent.notify('freehand-draw', { prop: 'isFHDIdx', value: { index: parseInt(id.split('_')[1], 10) - 1, obj: obj_3 } });
2450
+ if (obj_3['isIndex']) {
2451
+ isSelected = true;
2452
+ parent.notify('freehand-draw', { prop: 'selectFhd', value: { id: id } });
2453
+ if (!isBlazor()) {
2454
+ parent.notify('toolbar', { prop: 'renderQAT', onPropertyChange: false, value: { isPenEdit: true } });
2455
+ parent.notify('toolbar', { prop: 'update-toolbar-items', onPropertyChange: false });
2456
+ }
2457
+ else {
2458
+ parent.updateToolbar(parent.element, 'pen');
2459
+ parent.updateToolbar(parent.element, 'quickAccessToolbar', 'pen');
2460
+ }
2461
+ }
2462
+ else {
2463
+ isSelected = false;
2464
+ }
2465
+ }
2466
+ }
2467
+ obj['isSelected'] = isSelected;
2468
+ };
2469
+ Shape.prototype.deleteShape = function (id) {
2470
+ var parent = this.parent;
2471
+ if (!parent.disabled && parent.isImageLoaded) {
2472
+ this.applyActObj();
2473
+ if (id.split('_')[0] === 'shape') {
2474
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
2475
+ if (parent.objColl[i].currIndex === id) {
2476
+ parent.objColl.splice(i, 1);
2477
+ break;
2478
+ }
2479
+ }
2480
+ }
2481
+ else if (id.split('_')[0] === 'pen') {
2482
+ parent.notify('freehand-draw', { prop: 'handle-freehand-draw', value: { id: id } });
2483
+ }
2484
+ var object = { canvasFilter: null };
2485
+ parent.notify('toolbar', { prop: 'getCanvasFilter', onPropertyChange: false, value: { obj: object } });
2486
+ this.lowerContext.filter = object['canvasFilter'];
2487
+ this.lowerContext.clearRect(0, 0, parent.lowerCanvas.width, parent.lowerCanvas.height);
2488
+ parent.notify('draw', { prop: 'redrawImgWithObj', onPropertyChange: false });
2489
+ parent.notify('toolbar', { prop: 'refresh-main-toolbar', onPropertyChange: false });
2490
+ }
2491
+ };
2492
+ Shape.prototype.getMaxText = function (isTextBox, text, obj) {
2493
+ if (isNullOrUndefined(text)) {
2494
+ text = isTextBox ? this.parent.textArea.value : this.parent.activeObj.keyHistory;
2495
+ }
2496
+ var maxi;
2497
+ var rows = text.split('\n');
2498
+ var maxStr = rows[0].length;
2499
+ var maxText = rows[0];
2500
+ for (var i = 1; i < rows.length; i++) {
2501
+ maxi = rows[i].length;
2502
+ if (maxi > maxStr) {
2503
+ maxText = rows[i];
2504
+ maxStr = maxi;
2505
+ }
2506
+ }
2507
+ if (obj) {
2508
+ obj['maxText'] = maxText;
2509
+ }
2510
+ return maxText;
2511
+ };
2512
+ Shape.prototype.getLinePoints = function (x1, y1, x2, y2) {
2513
+ var points = [];
2514
+ var i;
2515
+ var j;
2516
+ if (x1 === x2) {
2517
+ if (y1 < y2) {
2518
+ i = [x1, y1];
2519
+ j = [x2, y2];
2520
+ }
2521
+ else {
2522
+ j = [x1, y1];
2523
+ i = [x2, y2];
2524
+ }
2525
+ var m = this.getSlope(i, j, true);
2526
+ var b = this.getIntercept(i, m);
2527
+ for (var y = i[1]; y <= j[1]; y++) {
2528
+ var x = m * y + b;
2529
+ points.push({ x: x, y: y });
2530
+ }
2531
+ }
2532
+ else {
2533
+ if (x1 < x2) {
2534
+ i = [x1, y1];
2535
+ j = [x2, y2];
2536
+ }
2537
+ else {
2538
+ j = [x1, y1];
2539
+ i = [x2, y2];
2540
+ }
2541
+ var m = this.getSlope(i, j, false);
2542
+ var b = this.getIntercept(i, m);
2543
+ for (var x = i[0]; x <= j[0]; x++) {
2544
+ var y = m * x + b;
2545
+ points.push({ x: x, y: y });
2546
+ }
2547
+ }
2548
+ if (Math.floor(x1) === Math.floor(x2) || (points.length < 10 && (y2 - y1 > 10 || y1 - y2 > 10))) {
2549
+ points = [];
2550
+ var lesserY = Math.min(y1, y2);
2551
+ for (var i_1 = 0; i_1 < Math.abs(Math.floor(y2) - Math.floor(y1)); i_1++) {
2552
+ points.push({ x: x1, y: lesserY + i_1 });
2553
+ }
2554
+ if (points.length > 1) {
2555
+ var prev = void 0;
2556
+ if (isNullOrUndefined(points[points.length - 2])) {
2557
+ prev = { x: 0, y: 0 };
2558
+ }
2559
+ else {
2560
+ prev = points[points.length - 2];
2561
+ }
2562
+ var diffX = points[points.length - 1]['x'] - prev.x;
2563
+ var diffY = points[points.length - 1]['y'] - prev.y;
2564
+ points.push({ x: points[points.length - 1]['x'] + (diffX / 2), y: points[points.length - 1]['y'] + (diffY / 2) });
2565
+ }
2566
+ }
2567
+ else if (Math.floor(y1) === Math.floor(y2) || (points.length < 10 && (x2 - x1 > 10 || x1 - x2 > 10))) {
2568
+ points = [];
2569
+ var lesserX = Math.min(x1, x2);
2570
+ for (var i_2 = 0; i_2 < Math.abs(Math.floor(x2) - Math.floor(x1)); i_2++) {
2571
+ points.push({ x: lesserX + i_2, y: y1 });
2572
+ }
2573
+ if (points.length > 1) {
2574
+ var prev = void 0;
2575
+ if (isNullOrUndefined(points[points.length - 2])) {
2576
+ prev = { x: 0, y: 0 };
2577
+ }
2578
+ else {
2579
+ prev = points[points.length - 2];
2580
+ }
2581
+ var diffX = points[points.length - 1]['x'] - prev.x;
2582
+ var diffY = points[points.length - 1]['y'] - prev.y;
2583
+ points.push({ x: points[points.length - 1]['x'] + (diffX / 2), y: points[points.length - 1]['y'] + (diffY / 2) });
2584
+ }
2585
+ }
2586
+ return points;
2587
+ };
2588
+ Shape.prototype.getSlope = function (a, b, isSameAxis) {
2589
+ var slope;
2590
+ if (isSameAxis) {
2591
+ if (a[1] === b[1]) {
2592
+ return null;
2593
+ }
2594
+ slope = (b[0] - a[0]) / (b[1] - a[1]);
2595
+ }
2596
+ else {
2597
+ if (a[0] === b[0]) {
2598
+ return null;
2599
+ }
2600
+ slope = (b[1] - a[1]) / (b[0] - a[0]);
2601
+ }
2602
+ return slope;
2603
+ };
2604
+ Shape.prototype.getIntercept = function (point, getSlope) {
2605
+ if (getSlope === null) {
2606
+ return point[0];
2607
+ }
2608
+ return point[1] - getSlope * point[0];
2609
+ };
2610
+ Shape.prototype.setPointCollForShapeRotation = function (obj) {
2611
+ var center = { x: obj.activePoint.startX + (obj.activePoint.width / 2), y: obj.activePoint.startY +
2612
+ (obj.activePoint.height / 2) };
2613
+ var p1 = { x: Math.cos(obj.rotatedAngle) * (obj.activePoint.startX - center.x) - Math.sin(obj.rotatedAngle) *
2614
+ (obj.activePoint.startY - center.y) + center.x,
2615
+ y: Math.sin(obj.rotatedAngle) * (obj.activePoint.startX - center.x) + Math.cos(obj.rotatedAngle) *
2616
+ (obj.activePoint.startY - center.y) + center.y };
2617
+ var p2 = { x: Math.cos(obj.rotatedAngle) * (obj.activePoint.endX - center.x) - Math.sin(obj.rotatedAngle) *
2618
+ (obj.activePoint.startY - center.y) + center.x,
2619
+ y: Math.sin(obj.rotatedAngle) * (obj.activePoint.endX - center.x) + Math.cos(obj.rotatedAngle) * (obj.activePoint.startY
2620
+ - center.y) + center.y };
2621
+ var p3 = { x: Math.cos(obj.rotatedAngle) * (obj.activePoint.startX - center.x) - Math.sin(obj.rotatedAngle) *
2622
+ (obj.activePoint.endY - center.y) + center.x,
2623
+ y: Math.sin(obj.rotatedAngle) * (obj.activePoint.startX - center.x) + Math.cos(obj.rotatedAngle) * (obj.activePoint.endY
2624
+ - center.y) + center.y };
2625
+ var p4 = { x: Math.cos(obj.rotatedAngle) * (obj.activePoint.endX - center.x) - Math.sin(obj.rotatedAngle) *
2626
+ (obj.activePoint.endY - center.y) + center.x,
2627
+ y: Math.sin(obj.rotatedAngle) * (obj.activePoint.endX - center.x) + Math.cos(obj.rotatedAngle) * (obj.activePoint.endY
2628
+ - center.y) + center.y };
2629
+ obj.horTopLinePointColl = this.getLinePoints(p1.x, p1.y, p2.x, p2.y);
2630
+ obj.horBottomLinePointColl = this.getLinePoints(p3.x, p3.y, p4.x, p4.y);
2631
+ obj.verLeftLinePointColl = this.getLinePoints(p1.x, p1.y, p3.x, p3.y);
2632
+ obj.verRightLinePointColl = this.getLinePoints(p2.x, p2.y, p4.x, p4.y);
2633
+ obj.verLeftLinePointColl.reverse();
2634
+ obj.verRightLinePointColl.reverse();
2635
+ // Updating ratio for point collection
2636
+ for (var i = 0; i < obj.horTopLinePointColl.length; i++) {
2637
+ obj.horTopLinePointColl[i].ratioX = (obj.horTopLinePointColl[i].x -
2638
+ this.parent.img.destLeft) / this.parent.img.destWidth;
2639
+ obj.horTopLinePointColl[i].ratioY = (obj.horTopLinePointColl[i].y -
2640
+ this.parent.img.destTop) / this.parent.img.destHeight;
2641
+ }
2642
+ for (var i = 0; i < obj.horBottomLinePointColl.length; i++) {
2643
+ obj.horBottomLinePointColl[i].ratioX = (obj.horBottomLinePointColl[i].x -
2644
+ this.parent.img.destLeft) / this.parent.img.destWidth;
2645
+ obj.horBottomLinePointColl[i].ratioY = (obj.horBottomLinePointColl[i].y -
2646
+ this.parent.img.destTop) / this.parent.img.destHeight;
2647
+ }
2648
+ for (var i = 0; i < obj.verLeftLinePointColl.length; i++) {
2649
+ obj.verLeftLinePointColl[i].ratioX = (obj.verLeftLinePointColl[i].x -
2650
+ this.parent.img.destLeft) / this.parent.img.destWidth;
2651
+ obj.verLeftLinePointColl[i].ratioY = (obj.verLeftLinePointColl[i].y -
2652
+ this.parent.img.destTop) / this.parent.img.destHeight;
2653
+ }
2654
+ for (var i = 0; i < obj.verRightLinePointColl.length; i++) {
2655
+ obj.verRightLinePointColl[i].ratioX = (obj.verRightLinePointColl[i].x -
2656
+ this.parent.img.destLeft) / this.parent.img.destWidth;
2657
+ obj.verRightLinePointColl[i].ratioY = (obj.verRightLinePointColl[i].y -
2658
+ this.parent.img.destTop) / this.parent.img.destHeight;
2659
+ }
2660
+ if (this.parent.upperCanvas.style.cursor !== 'move') {
2661
+ var object = { rotationCirclePoint: null };
2662
+ this.parent.notify('selection', { prop: 'getTransRotationPoint', value: { obj: obj, object: object } });
2663
+ var rotationCirclePoint = object['rotationCirclePoint'];
2664
+ if (rotationCirclePoint) {
2665
+ obj.rotationCirclePointColl = { x: Math.cos(obj.rotatedAngle) * (rotationCirclePoint.x - center.x) -
2666
+ Math.sin(obj.rotatedAngle) * (rotationCirclePoint.y - center.y) + center.x,
2667
+ y: Math.sin(obj.rotatedAngle) * (rotationCirclePoint.x - center.x) + Math.cos(obj.rotatedAngle)
2668
+ * (rotationCirclePoint.y - center.y) + center.y };
2669
+ obj.rotationCirclePointColl.ratioX = (obj.rotationCirclePointColl.x - this.parent.img.destLeft) /
2670
+ this.parent.img.destWidth;
2671
+ obj.rotationCirclePointColl.ratioY = (obj.rotationCirclePointColl.y - this.parent.img.destTop) /
2672
+ this.parent.img.destHeight;
2673
+ }
2674
+ }
2675
+ };
2676
+ Shape.prototype.getSquarePointForRotatedShape = function (obj, object) {
2677
+ var point = { startX: 0, startY: 0, endX: 0, endY: 0, width: 0, height: 0 };
2678
+ var center = { x: obj.activePoint.startX + (obj.activePoint.width / 2), y: obj.activePoint.startY +
2679
+ (obj.activePoint.height / 2) };
2680
+ var p1 = { x: Math.cos(obj.rotatedAngle) * (obj.activePoint.startX - center.x) - Math.sin(obj.rotatedAngle)
2681
+ * (obj.activePoint.startY - center.y) + center.x,
2682
+ y: Math.sin(obj.rotatedAngle) * (obj.activePoint.startX - center.x) + Math.cos(obj.rotatedAngle) * (obj.activePoint.startY
2683
+ - center.y) + center.y };
2684
+ var p2 = { x: Math.cos(obj.rotatedAngle) * (obj.activePoint.endX - center.x) - Math.sin(obj.rotatedAngle) *
2685
+ (obj.activePoint.startY - center.y) + center.x,
2686
+ y: Math.sin(obj.rotatedAngle) * (obj.activePoint.endX - center.x) + Math.cos(obj.rotatedAngle) * (obj.activePoint.startY
2687
+ - center.y) + center.y };
2688
+ var p3 = { x: Math.cos(obj.rotatedAngle) * (obj.activePoint.startX - center.x) - Math.sin(obj.rotatedAngle) *
2689
+ (obj.activePoint.endY - center.y) + center.x,
2690
+ y: Math.sin(obj.rotatedAngle) * (obj.activePoint.startX - center.x) + Math.cos(obj.rotatedAngle) * (obj.activePoint.endY
2691
+ - center.y) + center.y };
2692
+ var p4 = { x: Math.cos(obj.rotatedAngle) * (obj.activePoint.endX - center.x) - Math.sin(obj.rotatedAngle) *
2693
+ (obj.activePoint.endY - center.y) + center.x,
2694
+ y: Math.sin(obj.rotatedAngle) * (obj.activePoint.endX - center.x) + Math.cos(obj.rotatedAngle) *
2695
+ (obj.activePoint.endY - center.y) + center.y };
2696
+ point.startX = p1.x;
2697
+ point.startY = p1.y;
2698
+ point.endX = p1.x;
2699
+ point.endY = p1.y;
2700
+ if (point.startX > p2.x) {
2701
+ point.startX = p2.x;
2702
+ }
2703
+ if (point.startX > p3.x) {
2704
+ point.startX = p3.x;
2705
+ }
2706
+ if (point.startX > p4.x) {
2707
+ point.startX = p4.x;
2708
+ }
2709
+ if (point.startY > p2.y) {
2710
+ point.startY = p2.y;
2711
+ }
2712
+ if (point.startY > p3.y) {
2713
+ point.startY = p3.y;
2714
+ }
2715
+ if (point.startY > p4.y) {
2716
+ point.startY = p4.y;
2717
+ }
2718
+ if (point.endX < p2.x) {
2719
+ point.endX = p2.x;
2720
+ }
2721
+ if (point.endX < p3.x) {
2722
+ point.endX = p3.x;
2723
+ }
2724
+ if (point.endX < p4.x) {
2725
+ point.endX = p4.x;
2726
+ }
2727
+ if (point.endY < p2.y) {
2728
+ point.endY = p2.y;
2729
+ }
2730
+ if (point.endY < p3.y) {
2731
+ point.endY = p3.y;
2732
+ }
2733
+ if (point.endY < p4.y) {
2734
+ point.endY = p4.y;
2735
+ }
2736
+ point.width = point.endX - point.startX;
2737
+ point.height = point.endY - point.startY;
2738
+ if (object) {
2739
+ object['activePoint'] = point;
2740
+ }
2741
+ return point;
2742
+ };
2743
+ return Shape;
2744
+ }());
2745
+ export { Shape };