@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,4518 @@
1
+ import { Browser, EventHandler, extend, isBlazor, isNullOrUndefined } from '@syncfusion/ej2-base';
2
+ import { ZoomTrigger } from '../index';
3
+ var Selection = /** @class */ (function () {
4
+ function Selection(parent) {
5
+ this.diffPoint = { x: 0, y: 0 }; // updates resize points
6
+ this.oldPoint = {};
7
+ this.isTouch = false;
8
+ this.isObjSelected = false;
9
+ this.isFhdPoint = false; // Specifies whether mouse cursor is on freehand drawing point or not
10
+ this.dragPoint = { startX: 0, startY: 0, endX: 0, endY: 0 }; // updates drag start and end points in mousedown and mousemove
11
+ this.isShapeInserted = false;
12
+ this.tempActiveObj = { activePoint: { startX: 0, startY: 0, endX: 0, endY: 0, width: 0, height: 0 },
13
+ flipObjColl: [], triangle: [], triangleRatio: [] }; // for undo redo
14
+ this.isFirstMove = false; // for pinch zoom
15
+ this.startTouches = []; // for pinch zoom
16
+ this.tempTouches = []; // for pinch zoom
17
+ this.currMousePoint = { x: 0, y: 0 }; // To prevent mouse move event on pinch zoom
18
+ this.cursorTargetId = '';
19
+ this.isPreventDragging = false; // Shapes dragging is prevented when crop region is inside shape points
20
+ this.dragElement = '';
21
+ this.textRow = 1; // text area row count
22
+ this.mouseDownPoint = { x: 0, y: 0 };
23
+ this.previousPoint = { x: 0, y: 0 }; // updates prev x and y points in mouseMove
24
+ this.zoomType = 'Toolbar';
25
+ this.isInitialTextEdited = false;
26
+ this.dragCanvas = false;
27
+ this.isFhdCustomized = false;
28
+ this.touchEndPoint = {};
29
+ this.isFhdEditing = false; // Specifies whether freehand drawing is in editing mode or not
30
+ this.currentDrawingShape = '';
31
+ this.initialPrevObj = {};
32
+ this.touchTime = 0;
33
+ this.resizedElement = '';
34
+ this.parent = parent;
35
+ this.addEventListener();
36
+ }
37
+ Selection.prototype.destroy = function () {
38
+ if (this.parent.isDestroyed) {
39
+ return;
40
+ }
41
+ this.removeEventListener();
42
+ };
43
+ Selection.prototype.addEventListener = function () {
44
+ this.parent.on('selection', this.selection, this);
45
+ this.parent.on('destroyed', this.destroy, this);
46
+ };
47
+ Selection.prototype.removeEventListener = function () {
48
+ this.parent.off('selection', this.selection);
49
+ this.parent.off('destroyed', this.destroy);
50
+ };
51
+ Selection.prototype.selection = function (args) {
52
+ var _this = this;
53
+ this.updatePrivateVariables();
54
+ switch (args.prop) {
55
+ case 'mouse-up':
56
+ this.selMouseUpEvent();
57
+ break;
58
+ case 'setCursor':
59
+ this.setCursor(args.value['x'], args.value['y']);
60
+ break;
61
+ case 'updateActivePoint':
62
+ this.updateActivePoint(args.value['x'], args.value['y'], args.value['isCropSelection']);
63
+ break;
64
+ case 'updateCursorStyles':
65
+ this.updateCursorStyles(args.value['x'], args.value['y'], args.value['type']);
66
+ break;
67
+ case 'setTextSelection':
68
+ this.setTextSelection(args.value['width'], args.value['height']);
69
+ break;
70
+ case 'setActivePoint':
71
+ this.setActivePoint(args.value['startX'], args.value['startY']);
72
+ break;
73
+ case 'clearSelection':
74
+ this.clearSelection();
75
+ break;
76
+ case 'calcShapeRatio':
77
+ this.calcShapeRatio(args.value['x'], args.value['y'], args.value['imgWidth'], args.value['imgHeight']);
78
+ break;
79
+ case 'applyCurrShape':
80
+ this.applyCurrShape(args.value['isShapeClick']);
81
+ break;
82
+ case 'tab':
83
+ this.performTabAction();
84
+ break;
85
+ case 'setDragDirection':
86
+ this.setDragDirection(args.value['width'], args.value['height']);
87
+ break;
88
+ case 'clearUpperCanvas':
89
+ if (this.isTouch) {
90
+ setTimeout(function () {
91
+ _this.parent.upperCanvas.getContext('2d').clearRect(0, 0, _this.parent.upperCanvas.width, _this.parent.upperCanvas.height);
92
+ }, 550);
93
+ }
94
+ break;
95
+ case 'resetFreehandDrawVariables':
96
+ this.isFhdEditing = this.isFhdPoint = false;
97
+ break;
98
+ case 'isShapeInserted':
99
+ this.isShapeInserted = args.value['bool'];
100
+ break;
101
+ case 'redrawShape':
102
+ this.redrawShape(args.value['obj']);
103
+ break;
104
+ case 'setTextBoxStylesToActObj':
105
+ this.setTextBoxStylesToActObj();
106
+ break;
107
+ case 'mouseDownEventHandler':
108
+ this.mouseDownEventHandler(args.value['e']);
109
+ break;
110
+ case 'mouseMoveEventHandler':
111
+ this.mouseMoveEventHandler(args.value['e']);
112
+ break;
113
+ case 'mouseUpEventHandler':
114
+ this.mouseUpEventHandler(args.value['e']);
115
+ break;
116
+ case 'canvasMouseDownHandler':
117
+ this.canvasMouseDownHandler(args.value['e']);
118
+ break;
119
+ case 'canvasMouseMoveHandler':
120
+ this.canvasMouseMoveHandler(args.value['e']);
121
+ break;
122
+ case 'canvasMouseUpHandler':
123
+ this.canvasMouseUpHandler(args.value['e']);
124
+ break;
125
+ case 'touchStartHandler':
126
+ this.touchStartHandler(args.value['e']);
127
+ break;
128
+ case 'keyDownEventHandler':
129
+ this.keyDownEventHandler(args.value['e']);
130
+ break;
131
+ case 'handleScroll':
132
+ this.handleScroll(args.value['e']);
133
+ break;
134
+ case 'textKeyDown':
135
+ setTimeout(this.textKeyDown.bind(this), 1, args.value['e']);
136
+ break;
137
+ case 'deleteItem':
138
+ this.deleteItem();
139
+ break;
140
+ case 'updatePrevShapeSettings':
141
+ this.updatePrevShapeSettings(args.value['obj']);
142
+ break;
143
+ case 'getZoomType':
144
+ args.value['obj']['zoomType'] = this.zoomType;
145
+ break;
146
+ case 'setZoomType':
147
+ this.zoomType = args.value['zoomType'];
148
+ break;
149
+ case 'setInitialTextEdit':
150
+ this.isInitialTextEdited = args.value['bool'];
151
+ break;
152
+ case 'setDragCanvas':
153
+ this.dragCanvas = args.value['bool'];
154
+ break;
155
+ case 'setFreehandDrawCustomized':
156
+ this.isFhdCustomized = args.value['isFreehandDrawCustomized'];
157
+ break;
158
+ case 'setTouchEndPoint':
159
+ this.touchEndPoint.x = args.value['x'];
160
+ this.touchEndPoint.y = args.value['y'];
161
+ break;
162
+ case 'getPanDown':
163
+ args.value['obj']['panDown'] = this.panDown;
164
+ break;
165
+ case 'setPanDown':
166
+ this.panDown = args.value['panDown'];
167
+ break;
168
+ case 'getFreehandDrawEditing':
169
+ args.value['obj']['bool'] = this.isFhdEditing;
170
+ break;
171
+ case 'setFreehandDrawEditing':
172
+ this.isFhdEditing = args.value['bool'];
173
+ break;
174
+ case 'getTempActObj':
175
+ args.value['obj']['tempObj'] = this.tempActiveObj;
176
+ break;
177
+ case 'setTempActObj':
178
+ this.tempActiveObj = args.value['obj'];
179
+ break;
180
+ case 'isInside':
181
+ this.isInside(args.value['x'], args.value['y'], args.value['z1'], args.value['z2'], args.value['z3'], args.value['z4']);
182
+ break;
183
+ case 'setDragElement':
184
+ this.dragElement = args.value['value'];
185
+ break;
186
+ case 'setObjSelected':
187
+ this.isObjSelected = args.value['bool'];
188
+ break;
189
+ case 'adjustActObjForLineArrow':
190
+ this.adjustActObjForLineArrow(args.value['obj']);
191
+ break;
192
+ case 'findTarget':
193
+ this.findTarget(args.value['x'], args.value['y'], args.value['type']);
194
+ break;
195
+ case 'getCurrentFlipState':
196
+ this.getCurrentFlipState();
197
+ break;
198
+ case 'setDragWidth':
199
+ this.setDragWidth(args.value['width']);
200
+ break;
201
+ case 'setDragHeight':
202
+ this.setDragHeight(args.value['setDragHeight']);
203
+ break;
204
+ case 'annotate':
205
+ this.currentDrawingShape = args.value['shape'];
206
+ if (args.value['shape'] === 'text') {
207
+ this.parent.activeObj.textSettings.fontSize = 100;
208
+ this.parent.activeObj.keyHistory = 'Enter Text';
209
+ this.parent.notify('shape', { prop: 'initializeTextShape', onPropertyChange: false,
210
+ value: { text: null, fontFamily: null, fontSize: null, bold: null, italic: null, strokeColor: null } });
211
+ }
212
+ else if (args.value['shape'] === 'path') {
213
+ this.parent.activeObj.pointColl = [];
214
+ }
215
+ break;
216
+ case 'getCurrentDrawingShape':
217
+ args.value['obj']['shape'] = this.currentDrawingShape;
218
+ break;
219
+ case 'setCurrentDrawingShape':
220
+ this.currentDrawingShape = args.value['value'];
221
+ break;
222
+ case 'getTransRotationPoint':
223
+ this.getTransRotationPoint(args.value['obj'], args.value['object']);
224
+ break;
225
+ case 'adjustNEPoints':
226
+ this.adjustNEPoints(args.value['rectangle'], args.value['x'], args.value['y'], args.value['angle']);
227
+ break;
228
+ case 'adjustRotationPoints':
229
+ this.adjustRotationPoints(args.value['rectangle'], args.value['x'], args.value['y'], args.value['angle']);
230
+ break;
231
+ case 'getResizeDirection':
232
+ this.getResizeDirection(args.value['rectangle'], args.value['x'], args.value['y'], args.value['angle']);
233
+ break;
234
+ case 'setResizedElement':
235
+ this.resizedElement = args.value['value'];
236
+ break;
237
+ case 'reset':
238
+ this.reset();
239
+ break;
240
+ }
241
+ };
242
+ Selection.prototype.getModuleName = function () {
243
+ return 'selection';
244
+ };
245
+ Selection.prototype.updatePrivateVariables = function () {
246
+ var parent = this.parent;
247
+ if (parent.lowerCanvas) {
248
+ this.lowerContext = parent.lowerCanvas.getContext('2d');
249
+ }
250
+ if (parent.upperCanvas) {
251
+ this.upperContext = parent.upperCanvas.getContext('2d');
252
+ }
253
+ };
254
+ Selection.prototype.reset = function () {
255
+ this.diffPoint = { x: 0, y: 0 };
256
+ this.oldPoint = {};
257
+ this.isTouch = this.isObjSelected = this.isFhdPoint = this.isShapeInserted = false;
258
+ this.dragPoint = { startX: 0, startY: 0, endX: 0, endY: 0 };
259
+ this.tempActiveObj = { activePoint: { startX: 0, startY: 0, endX: 0, endY: 0, width: 0, height: 0 },
260
+ flipObjColl: [], triangle: [], triangleRatio: [] };
261
+ this.isFirstMove = false;
262
+ this.cursorTargetId = this.dragElement = '';
263
+ this.startTouches = [];
264
+ this.tempTouches = [];
265
+ this.currMousePoint = { x: 0, y: 0 };
266
+ this.isPreventDragging = false;
267
+ this.timer = undefined;
268
+ this.tempObjColl = undefined;
269
+ this.textRow = 1;
270
+ this.mouseDownPoint = { x: 0, y: 0 };
271
+ this.previousPoint = { x: 0, y: 0 };
272
+ this.zoomType = 'Toolbar';
273
+ this.isInitialTextEdited = false;
274
+ this.dragCanvas = false;
275
+ this.isFhdCustomized = false;
276
+ this.touchEndPoint = {};
277
+ this.panDown = null;
278
+ this.isFhdEditing = false;
279
+ this.pathAdjustedIndex = null;
280
+ this.touchTime = 0;
281
+ this.currentDrawingShape = '';
282
+ this.initialPrevObj = {};
283
+ this.resizedElement = '';
284
+ };
285
+ Selection.prototype.performTabAction = function () {
286
+ if (this.parent.textArea.style.display === 'block') {
287
+ var allowUndoRedoPush = this.applyCurrShape(false);
288
+ this.parent.notify('shape', { prop: 'redrawActObj', onPropertyChange: false,
289
+ value: { x: null, y: null, isMouseDown: null } });
290
+ if (allowUndoRedoPush) {
291
+ this.parent.notify('undo-redo', { prop: 'updateCurrUrc', value: { type: 'ok' } });
292
+ }
293
+ }
294
+ };
295
+ Selection.prototype.selMouseUpEvent = function () {
296
+ this.oldPoint.x = undefined;
297
+ this.oldPoint.y = undefined;
298
+ };
299
+ Selection.prototype.getMouseCursor = function (actObj, x, y, isCropSelection, isApply) {
300
+ var rotationCirclePoint = this.getTransRotationPoint(actObj);
301
+ var cursor = 'default';
302
+ var ratio = isApply ? 0 : ((actObj.topLeftCircle.radius * 2));
303
+ if (x >= (actObj.topLeftCircle.startX - ratio) &&
304
+ x <= (actObj.topLeftCircle.startX + ratio) &&
305
+ y >= (actObj.topLeftCircle.startY - ratio) &&
306
+ y <= (actObj.topLeftCircle.startY + ratio)) {
307
+ cursor = 'nw-resize';
308
+ }
309
+ else if (x >= (actObj.topLeftCircle.startX - ratio) &&
310
+ x <= (actObj.topRightCircle.startX - ratio) &&
311
+ y >= (actObj.topCenterCircle.startY - ratio) &&
312
+ y <= (actObj.topCenterCircle.startY + ratio)) {
313
+ cursor = 'n-resize';
314
+ }
315
+ else if (x >= (actObj.topRightCircle.startX - ratio) &&
316
+ x <= (actObj.topRightCircle.startX + ratio) &&
317
+ y >= (actObj.topRightCircle.startY - ratio) &&
318
+ y <= (actObj.topRightCircle.startY + ratio)) {
319
+ cursor = 'ne-resize';
320
+ }
321
+ else if (x >= (actObj.centerLeftCircle.startX - ratio) &&
322
+ x <= (actObj.centerLeftCircle.startX + ratio) &&
323
+ y >= (actObj.topLeftCircle.startY - ratio) &&
324
+ y <= (actObj.bottomLeftCircle.startY - ratio)) {
325
+ cursor = 'w-resize';
326
+ }
327
+ else if (x >= (actObj.centerRightCircle.startX - ratio) &&
328
+ x <= (actObj.centerRightCircle.startX + ratio) &&
329
+ y >= (actObj.topRightCircle.startY - ratio) &&
330
+ y <= (actObj.bottomRightCircle.startY - ratio)) {
331
+ cursor = 'e-resize';
332
+ }
333
+ else if (x >= (actObj.bottomLeftCircle.startX - ratio) &&
334
+ x <= (actObj.bottomLeftCircle.startX + ratio) &&
335
+ y >= (actObj.bottomLeftCircle.startY - ratio) &&
336
+ y <= (actObj.bottomLeftCircle.startY + ratio)) {
337
+ cursor = 'sw-resize';
338
+ }
339
+ else if (x >= (actObj.bottomLeftCircle.startX - ratio) &&
340
+ x <= (actObj.bottomRightCircle.startX - ratio) &&
341
+ y >= (actObj.bottomCenterCircle.startY - ratio) &&
342
+ y <= (actObj.bottomCenterCircle.startY + ratio)) {
343
+ cursor = 's-resize';
344
+ }
345
+ else if (x >= (actObj.bottomRightCircle.startX - ratio) &&
346
+ x <= (actObj.bottomRightCircle.startX + ratio) &&
347
+ y >= (actObj.bottomRightCircle.startY - ratio) &&
348
+ y <= (actObj.bottomRightCircle.startY + ratio)) {
349
+ cursor = 'se-resize';
350
+ }
351
+ else if ((x >= actObj.activePoint.startX &&
352
+ x <= actObj.activePoint.endX) && (y >= actObj.activePoint.startY &&
353
+ y <= actObj.activePoint.endY)) {
354
+ if (isCropSelection) {
355
+ cursor = 'grab';
356
+ }
357
+ else {
358
+ cursor = 'move';
359
+ }
360
+ }
361
+ else if (rotationCirclePoint && !isApply &&
362
+ x >= (rotationCirclePoint.x - (actObj.bottomCenterCircle.radius + 2)) &&
363
+ x <= rotationCirclePoint.x + (actObj.bottomCenterCircle.radius + 2) &&
364
+ y >= rotationCirclePoint.y - (actObj.bottomCenterCircle.radius + 2) &&
365
+ y <= rotationCirclePoint.y + (actObj.bottomCenterCircle.radius + 2)) {
366
+ cursor = 'grabbing';
367
+ }
368
+ else {
369
+ cursor = 'default';
370
+ }
371
+ return cursor;
372
+ };
373
+ Selection.prototype.setCursor = function (x, y) {
374
+ var parent = this.parent;
375
+ var lowerCanvas = document.querySelector('#' + parent.element.id + '_lowerCanvas');
376
+ var upperCanvas = document.querySelector('#' + parent.element.id + '_upperCanvas');
377
+ var isCropSelection = false;
378
+ var splitWords;
379
+ if (this.currentDrawingShape !== '') {
380
+ upperCanvas.style.cursor = parent.cursor = 'crosshair';
381
+ return;
382
+ }
383
+ if (parent.currObjType.isDragging) {
384
+ if (this.dragElement === '') {
385
+ upperCanvas.style.cursor = parent.cursor = 'move';
386
+ }
387
+ else {
388
+ upperCanvas.style.cursor = parent.cursor = this.dragElement;
389
+ }
390
+ return;
391
+ }
392
+ if (parent.activeObj.horTopLine !== undefined) {
393
+ if (parent.activeObj.shape !== undefined) {
394
+ splitWords = parent.activeObj.shape.split('-');
395
+ }
396
+ if (splitWords === undefined && parent.currObjType.isCustomCrop) {
397
+ isCropSelection = true;
398
+ }
399
+ else if (splitWords !== undefined && splitWords[0] === 'crop') {
400
+ isCropSelection = true;
401
+ }
402
+ if (!isCropSelection && parent.togglePan) {
403
+ lowerCanvas.style.cursor = upperCanvas.style.cursor = parent.cursor = 'grab';
404
+ }
405
+ var cursor = upperCanvas.style.cursor;
406
+ var actObj = extend({}, parent.activeObj, {}, true);
407
+ this.cursorTargetId = actObj.currIndex;
408
+ var degree = void 0;
409
+ if (actObj.shapeDegree === 0) {
410
+ degree = parent.transform.degree;
411
+ }
412
+ else {
413
+ degree = parent.transform.degree - actObj.shapeDegree;
414
+ }
415
+ if (degree < 0) {
416
+ degree = 360 + degree;
417
+ }
418
+ if (actObj.shape === 'line' || actObj.shape === 'arrow') {
419
+ this.setCursorForLineArrow(actObj, x, y, upperCanvas);
420
+ }
421
+ else if (actObj.shape === 'path') {
422
+ this.setCursorForPath(actObj, x, y, upperCanvas);
423
+ }
424
+ else if (!isNullOrUndefined(actObj.rotatedAngle) && actObj.rotatedAngle !== 0) {
425
+ this.setCursorForRotatedObject(actObj, x, y, upperCanvas);
426
+ }
427
+ else {
428
+ upperCanvas.style.cursor = parent.cursor = this.getMouseCursor(actObj, x, y, isCropSelection, false);
429
+ if ((actObj.shape === 'text') && (parent.cursor === 'n-resize' ||
430
+ parent.cursor === 's-resize' || parent.cursor === 'e-resize' ||
431
+ parent.cursor === 'w-resize')) {
432
+ upperCanvas.style.cursor = parent.cursor = 'move';
433
+ }
434
+ }
435
+ if (cursor === 'default' && parent.cursor === 'default' && isCropSelection) {
436
+ upperCanvas.style.cursor = parent.cursor = 'grab';
437
+ }
438
+ if (cursor === 'grab' && parent.cursor === 'default') {
439
+ upperCanvas.style.cursor = parent.cursor = 'grab';
440
+ }
441
+ }
442
+ else if (parent.togglePan && !parent.togglePen) {
443
+ lowerCanvas.style.cursor = upperCanvas.style.cursor = parent.cursor = 'grab';
444
+ }
445
+ else {
446
+ if (parent.currObjType.isCustomCrop || parent.togglePen) {
447
+ upperCanvas.style.cursor = parent.cursor = 'crosshair';
448
+ }
449
+ else {
450
+ upperCanvas.style.cursor = parent.cursor = 'default';
451
+ }
452
+ }
453
+ if (parent.cursor === 'default' || parent.cursor === 'grab') {
454
+ var cursor = upperCanvas.style.cursor;
455
+ if (parent.objColl.length > 0 && (parent.cursor !== 'grab' || !isCropSelection)) {
456
+ this.setCursorFromObj(x, y, parent.objColl, upperCanvas, isCropSelection);
457
+ }
458
+ if (cursor === 'grab' && parent.cursor === 'default') {
459
+ upperCanvas.style.cursor = parent.cursor = 'grab';
460
+ }
461
+ }
462
+ if ((parent.cursor === 'default' || parent.cursor === 'grab')
463
+ && parent.pointColl[0] && (parent.cursor !== 'grab' || !isCropSelection)
464
+ && !parent.currObjType.isDragging && !parent.currObjType.isResize) {
465
+ this.setCursorForFreehandDrawing(x, y, upperCanvas);
466
+ }
467
+ };
468
+ Selection.prototype.setCursorForPath = function (actObj, x, y, upperCanvas) {
469
+ this.setCursorForLineArrow(actObj, x, y, upperCanvas);
470
+ var parent = this.parent;
471
+ if (parent.cursor === 'default') {
472
+ var obj = extend({}, actObj, null, true);
473
+ var isMove = false;
474
+ for (var i = 1; i < actObj.pointColl.length; i++) {
475
+ if (isMove) {
476
+ break;
477
+ }
478
+ obj.activePoint.startX = actObj.pointColl[i - 1].x;
479
+ obj.activePoint.startY = actObj.pointColl[i - 1].y;
480
+ obj.activePoint.endX = actObj.pointColl[i].x;
481
+ obj.activePoint.endY = actObj.pointColl[i].y;
482
+ parent.notify('shape', { prop: 'setPointCollForLineArrow', onPropertyChange: false,
483
+ value: { obj: obj } });
484
+ for (var j = 0; j < obj.pointColl.length; j++) {
485
+ var point = obj.pointColl[j];
486
+ if (!isNullOrUndefined(point.x - (actObj.topLeftCircle.radius * 2)) &&
487
+ !isNullOrUndefined(point.x + (actObj.topLeftCircle.radius * 2)) &&
488
+ !isNullOrUndefined(point.y - (actObj.topLeftCircle.radius * 2)) &&
489
+ !isNullOrUndefined(point.y + (actObj.topLeftCircle.radius * 2)) &&
490
+ x >= (point.x - (actObj.topLeftCircle.radius * 2)) &&
491
+ x <= (point.x + (actObj.topLeftCircle.radius * 2)) &&
492
+ y >= (point.y - (actObj.topLeftCircle.radius * 2)) &&
493
+ y <= (point.y + (actObj.topLeftCircle.radius * 2))) {
494
+ upperCanvas.style.cursor = parent.cursor = 'move';
495
+ isMove = true;
496
+ break;
497
+ }
498
+ else {
499
+ upperCanvas.style.cursor = parent.cursor = 'default';
500
+ }
501
+ }
502
+ }
503
+ }
504
+ return parent.cursor;
505
+ };
506
+ Selection.prototype.setCursorForLineArrow = function (actObj, x, y, upperCanvas) {
507
+ var index;
508
+ for (var i = 0; i < actObj.pointColl.length; i++) {
509
+ var point = actObj.pointColl[i];
510
+ if (x >= (point.x - (actObj.topLeftCircle.radius * 2)) && x <= (point.x + (actObj.topLeftCircle.radius * 2)) &&
511
+ y >= (point.y - (actObj.topLeftCircle.radius * 2)) && y <= (point.y + (actObj.topLeftCircle.radius * 2))) {
512
+ upperCanvas.style.cursor = this.parent.cursor = 'move';
513
+ index = i;
514
+ break;
515
+ }
516
+ else {
517
+ upperCanvas.style.cursor = this.parent.cursor = 'default';
518
+ }
519
+ }
520
+ return index;
521
+ };
522
+ Selection.prototype.setCursorForRotatedObject = function (actObj, x, y, upperCanvas) {
523
+ this.resizedElement = '';
524
+ var parent = this.parent;
525
+ if (x >= (actObj.horTopLinePointColl[0].x - (actObj.bottomCenterCircle.radius + 2)) &&
526
+ x <= (actObj.horTopLinePointColl[0].x + (actObj.bottomCenterCircle.radius + 2)) &&
527
+ y >= (actObj.horTopLinePointColl[0].y - (actObj.bottomCenterCircle.radius + 2)) &&
528
+ y <= (actObj.horTopLinePointColl[0].y + (actObj.bottomCenterCircle.radius + 2))) {
529
+ upperCanvas.style.cursor = parent.cursor = 'nw-resize';
530
+ }
531
+ else if (x >= (actObj.horTopLinePointColl[Math.round(actObj.horTopLinePointColl.length / 2)].x - 5) &&
532
+ x <= (actObj.horTopLinePointColl[Math.round(actObj.horTopLinePointColl.length / 2)].x + 5) &&
533
+ y >= (actObj.horTopLinePointColl[Math.round(actObj.horTopLinePointColl.length / 2)].y - 5) &&
534
+ y <= (actObj.horTopLinePointColl[Math.round(actObj.horTopLinePointColl.length / 2)].y + 5)) {
535
+ upperCanvas.style.cursor = parent.cursor = this.resizedElement = 'n-resize';
536
+ }
537
+ else if (x >= (actObj.horTopLinePointColl[Math.round(actObj.horTopLinePointColl.length - 1)].x -
538
+ (actObj.bottomCenterCircle.radius + 2)) &&
539
+ x <= (actObj.horTopLinePointColl[Math.round(actObj.horTopLinePointColl.length - 1)].x +
540
+ (actObj.bottomCenterCircle.radius + 2)) &&
541
+ y >= (actObj.horTopLinePointColl[Math.round(actObj.horTopLinePointColl.length - 1)].y -
542
+ (actObj.bottomCenterCircle.radius + 2)) &&
543
+ y <= (actObj.horTopLinePointColl[Math.round(actObj.horTopLinePointColl.length - 1)].y +
544
+ (actObj.bottomCenterCircle.radius + 2))) {
545
+ upperCanvas.style.cursor = parent.cursor = 'ne-resize';
546
+ }
547
+ else if (x >= (actObj.verLeftLinePointColl[Math.round(actObj.verLeftLinePointColl.length / 2)].x - 5) &&
548
+ x <= (actObj.verLeftLinePointColl[Math.round(actObj.verLeftLinePointColl.length / 2)].x + 5) &&
549
+ y >= (actObj.verLeftLinePointColl[Math.round(actObj.verLeftLinePointColl.length / 2)].y - 5)
550
+ && y <= (actObj.verLeftLinePointColl[Math.round(actObj.verLeftLinePointColl.length / 2)].y + 5)) {
551
+ upperCanvas.style.cursor = parent.cursor = this.resizedElement = 'w-resize';
552
+ }
553
+ else if (x >= (actObj.verRightLinePointColl[Math.round(actObj.verRightLinePointColl.length / 2)].x - 5) &&
554
+ x <= (actObj.verRightLinePointColl[Math.round(actObj.verRightLinePointColl.length / 2)].x + 5)
555
+ && y >= (actObj.verRightLinePointColl[Math.round(actObj.verRightLinePointColl.length / 2)].y - 5) &&
556
+ y <= (actObj.verRightLinePointColl[Math.round(actObj.verRightLinePointColl.length / 2)].y + 5)) {
557
+ upperCanvas.style.cursor = parent.cursor = this.resizedElement = 'e-resize';
558
+ }
559
+ else if (x >= (actObj.horBottomLinePointColl[0].x - (actObj.bottomCenterCircle.radius + 2)) &&
560
+ x <= (actObj.horBottomLinePointColl[0].x + (actObj.bottomCenterCircle.radius + 2)) &&
561
+ y >= (actObj.horBottomLinePointColl[0].y - (actObj.bottomCenterCircle.radius + 2)) &&
562
+ y <= (actObj.horBottomLinePointColl[0].y + (actObj.bottomCenterCircle.radius + 2))) {
563
+ upperCanvas.style.cursor = parent.cursor = 'sw-resize';
564
+ }
565
+ else if (x >= (actObj.horBottomLinePointColl[Math.round(actObj.horBottomLinePointColl.length / 2)].x - 5) &&
566
+ x <= (actObj.horBottomLinePointColl[Math.round(actObj.horBottomLinePointColl.length / 2)].x + 5) &&
567
+ y >= (actObj.horBottomLinePointColl[Math.round(actObj.horBottomLinePointColl.length / 2)].y - 5) &&
568
+ y <= (actObj.horBottomLinePointColl[Math.round(actObj.horBottomLinePointColl.length / 2)].y + 5)) {
569
+ upperCanvas.style.cursor = parent.cursor = this.resizedElement = 's-resize';
570
+ }
571
+ else if (x >= (actObj.horBottomLinePointColl[Math.round(actObj.horBottomLinePointColl.length - 1)].x -
572
+ (actObj.bottomCenterCircle.radius + 2)) &&
573
+ x <= (actObj.horBottomLinePointColl[Math.round(actObj.horBottomLinePointColl.length - 1)].x +
574
+ (actObj.bottomCenterCircle.radius + 2)) &&
575
+ y >= (actObj.horBottomLinePointColl[Math.round(actObj.horBottomLinePointColl.length - 1)].y -
576
+ (actObj.bottomCenterCircle.radius + 2)) &&
577
+ y <= (actObj.horBottomLinePointColl[Math.round(actObj.horBottomLinePointColl.length - 1)].y +
578
+ (actObj.bottomCenterCircle.radius + 2))) {
579
+ upperCanvas.style.cursor = parent.cursor = 'se-resize';
580
+ }
581
+ else if (actObj.rotationCirclePointColl &&
582
+ x >= (actObj.rotationCirclePointColl.x - (actObj.bottomCenterCircle.radius + 2)) &&
583
+ x <= actObj.rotationCirclePointColl.x + (actObj.bottomCenterCircle.radius + 2) &&
584
+ y >= actObj.rotationCirclePointColl.y - (actObj.bottomCenterCircle.radius + 2) &&
585
+ y <= actObj.rotationCirclePointColl.y + (actObj.bottomCenterCircle.radius + 2)) {
586
+ upperCanvas.style.cursor = parent.cursor = 'grabbing';
587
+ }
588
+ else {
589
+ upperCanvas.style.cursor = parent.cursor = 'default';
590
+ var isPointsInsideRectangle = this.getRectanglePoints(actObj.activePoint.startX, actObj.activePoint.startY, actObj.activePoint.width, actObj.activePoint.height, actObj.rotatedAngle * (180 / Math.PI), x, y);
591
+ if (isPointsInsideRectangle) {
592
+ upperCanvas.style.cursor = parent.cursor = 'move';
593
+ }
594
+ }
595
+ if (parent.cursor === 'default') {
596
+ for (var i = 0, len = actObj.horTopLinePointColl.length; i < len; i++) {
597
+ if (x >= (actObj.horTopLinePointColl[i].x - 5) &&
598
+ x <= (actObj.horTopLinePointColl[i].x + 5) &&
599
+ y >= (actObj.horTopLinePointColl[i].y - 5) &&
600
+ y <= (actObj.horTopLinePointColl[i].y + 5)) {
601
+ upperCanvas.style.cursor = parent.cursor = this.resizedElement = 'n-resize';
602
+ break;
603
+ }
604
+ }
605
+ }
606
+ if (parent.cursor === 'default') {
607
+ for (var i = 0, len = actObj.horBottomLinePointColl.length; i < len; i++) {
608
+ if (x >= (actObj.horBottomLinePointColl[i].x - 5) &&
609
+ x <= (actObj.horBottomLinePointColl[i].x + 5) &&
610
+ y >= (actObj.horBottomLinePointColl[i].y - 5) &&
611
+ y <= (actObj.horBottomLinePointColl[i].y + 5)) {
612
+ upperCanvas.style.cursor = parent.cursor = this.resizedElement = 's-resize';
613
+ break;
614
+ }
615
+ }
616
+ }
617
+ if (parent.cursor === 'default') {
618
+ for (var i = 0, len = actObj.verLeftLinePointColl.length; i < len; i++) {
619
+ if (x >= (actObj.verLeftLinePointColl[i].x - 5) &&
620
+ x <= (actObj.verLeftLinePointColl[i].x + 5) &&
621
+ y >= (actObj.verLeftLinePointColl[i].y - 5) &&
622
+ y <= (actObj.verLeftLinePointColl[i].y + 5)) {
623
+ upperCanvas.style.cursor = parent.cursor = this.resizedElement = 'w-resize';
624
+ break;
625
+ }
626
+ }
627
+ }
628
+ if (parent.cursor === 'default') {
629
+ for (var i = 0, len = actObj.verRightLinePointColl.length; i < len; i++) {
630
+ if (x >= (actObj.verRightLinePointColl[i].x - 5) &&
631
+ x <= (actObj.verRightLinePointColl[i].x + 5) &&
632
+ y >= (actObj.verRightLinePointColl[i].y - 5) &&
633
+ y <= (actObj.verRightLinePointColl[i].y + 5)) {
634
+ upperCanvas.style.cursor = parent.cursor = this.resizedElement = 'e-resize';
635
+ break;
636
+ }
637
+ }
638
+ }
639
+ this.adjustCursorStylesForRotatedState(actObj);
640
+ return parent.cursor;
641
+ };
642
+ Selection.prototype.adjustCursorStylesForRotatedState = function (actObj) {
643
+ var parent = this.parent;
644
+ var length = actObj.rotatedAngle * (180 / Math.PI);
645
+ length = length > 0 ? Math.floor(length) : Math.ceil(length);
646
+ if ((length >= 92 && length <= 182) || (length >= -178 && length <= -88)) {
647
+ var cursorMap = { 'nw-resize': 'ne-resize', 'n-resize': 's-resize',
648
+ 'ne-resize': 'nw-resize', 'w-resize': 'e-resize', 'e-resize': 'w-resize',
649
+ 'sw-resize': 'se-resize', 's-resize': 'n-resize', 'se-resize': 'sw-resize'
650
+ };
651
+ if (parent.cursor in cursorMap) {
652
+ parent.cursor = cursorMap[parent.cursor];
653
+ }
654
+ }
655
+ parent.upperCanvas.style.cursor = this.getResizeElement((actObj.rotatedAngle * (180 / Math.PI)), parent.cursor);
656
+ return parent.cursor;
657
+ };
658
+ Selection.prototype.getResizeElement = function (degree, element) {
659
+ var resizeMappings = [];
660
+ if (element === 'nw-resize') {
661
+ resizeMappings = [
662
+ [337.5, 22.5, 'nw-resize'], [22.5, 67.5, 'n-resize'], [67.5, 112.5, 'ne-resize'],
663
+ [112.5, 157.5, 'e-resize'], [157.5, 202.5, 'se-resize'],
664
+ [202.5, 247.5, 's-resize'], [247.5, 292.5, 'sw-resize'],
665
+ [292.5, 337.5, 'w-resize']
666
+ ];
667
+ }
668
+ else if (element === 'n-resize') {
669
+ resizeMappings = [
670
+ [337.5, 22.5, 'n-resize'], [22.5, 67.5, 'ne-resize'], [67.5, 112.5, 'e-resize'],
671
+ [112.5, 157.5, 'se-resize'], [157.5, 202.5, 's-resize'], [202.5, 247.5, 'sw-resize'],
672
+ [247.5, 292.5, 'w-resize'], [292.5, 337.5, 'nw-resize']
673
+ ];
674
+ }
675
+ else if (element === 'ne-resize') {
676
+ resizeMappings = [
677
+ [337.5, 22.5, 'ne-resize'], [22.5, 67.5, 'e-resize'],
678
+ [67.5, 112.5, 'se-resize'], [112.5, 157.5, 's-resize'], [157.5, 202.5, 'sw-resize'],
679
+ [202.5, 247.5, 'w-resize'], [247.5, 292.5, 'nw-resize'], [292.5, 337.5, 'n-resize']
680
+ ];
681
+ }
682
+ else if (element === 'e-resize') {
683
+ resizeMappings = [
684
+ [337.5, 22.5, 'e-resize'], [22.5, 67.5, 'se-resize'], [67.5, 112.5, 's-resize'],
685
+ [112.5, 157.5, 'sw-resize'], [157.5, 202.5, 'w-resize'], [202.5, 247.5, 'nw-resize'],
686
+ [247.5, 292.5, 'n-resize'], [292.5, 337.5, 'ne-resize']
687
+ ];
688
+ }
689
+ else if (element === 'se-resize') {
690
+ resizeMappings = [
691
+ [337.5, 22.5, 'se-resize'], [22.5, 67.5, 's-resize'], [67.5, 112.5, 'sw-resize'],
692
+ [112.5, 157.5, 'w-resize'], [157.5, 202.5, 'nw-resize'], [202.5, 247.5, 'n-resize'],
693
+ [247.5, 292.5, 'ne-resize'], [292.5, 337.5, 'e-resize']
694
+ ];
695
+ }
696
+ else if (element === 's-resize') {
697
+ resizeMappings = [
698
+ [337.5, 22.5, 's-resize'], [22.5, 67.5, 'sw-resize'], [67.5, 112.5, 'w-resize'],
699
+ [112.5, 157.5, 'nw-resize'], [157.5, 202.5, 'n-resize'], [202.5, 247.5, 'ne-resize'],
700
+ [247.5, 292.5, 'e-resize'], [292.5, 337.5, 'se-resize']
701
+ ];
702
+ }
703
+ else if (element === 'sw-resize') {
704
+ resizeMappings = [
705
+ [337.5, 22.5, 'sw-resize'], [22.5, 67.5, 'w-resize'], [67.5, 112.5, 'nw-resize'],
706
+ [112.5, 157.5, 'n-resize'], [157.5, 202.5, 'ne-resize'], [202.5, 247.5, 'e-resize'],
707
+ [247.5, 292.5, 'se-resize'], [292.5, 337.5, 's-resize']
708
+ ];
709
+ }
710
+ else if (element === 'w-resize') {
711
+ resizeMappings = [
712
+ [337.5, 22.5, 'w-resize'], [22.5, 67.5, 'nw-resize'], [67.5, 112.5, 'n-resize'],
713
+ [112.5, 157.5, 'ne-resize'], [157.5, 202.5, 'e-resize'], [202.5, 247.5, 'se-resize'],
714
+ [247.5, 292.5, 's-resize'], [292.5, 337.5, 'sw-resize']
715
+ ];
716
+ }
717
+ var positiveDegree = degree < 0 ? 360 - Math.abs(degree) : degree;
718
+ for (var _i = 0, resizeMappings_1 = resizeMappings; _i < resizeMappings_1.length; _i++) {
719
+ var _a = resizeMappings_1[_i], startDegree = _a[0], endDegree = _a[1], resizeElement = _a[2];
720
+ if ((positiveDegree > startDegree && positiveDegree <= endDegree) ||
721
+ (positiveDegree + 360 > startDegree && positiveDegree + 360 <= endDegree)) {
722
+ return resizeElement;
723
+ }
724
+ }
725
+ return element;
726
+ };
727
+ Selection.prototype.setCursorForFreehandDrawing = function (x, y, upperCanvas) {
728
+ var upperContext = upperCanvas.getContext('2d');
729
+ var parent = this.parent;
730
+ var textArea = document.querySelector('#' + parent.element.id + '_textArea');
731
+ var isEntered = false;
732
+ parent.notify('freehand-draw', { prop: 'setFreehandDrawHoveredIndex', onPropertyChange: false,
733
+ value: { index: -1 } });
734
+ var sPoints;
735
+ for (var n = 0; n < parent.freehandCounter; n++) {
736
+ var obj = { selPointColl: {} };
737
+ parent.notify('freehand-draw', { prop: 'getSelPointColl', onPropertyChange: false, value: { obj: obj } });
738
+ sPoints = extend([], obj['selPointColl'][n].points, []);
739
+ parent.points = extend([], parent.pointColl[n].points, []);
740
+ parent.notify('freehand-draw', { prop: 'setPointCounter', onPropertyChange: false, value: { value: 0 } });
741
+ var len = sPoints.length;
742
+ for (var l = 0; l < len; l++) {
743
+ if (l !== 0) {
744
+ var isInside = false;
745
+ if (sPoints[l - 1] && sPoints[l]) {
746
+ isInside = this.isInside(x, y, sPoints[l - 1].x, sPoints[l - 1].y, sPoints[l].x, sPoints[l].y);
747
+ }
748
+ if (isInside) {
749
+ this.isFhdPoint = true;
750
+ parent.notify('freehand-draw', { prop: 'setFreehandDrawHoveredIndex', onPropertyChange: false,
751
+ value: { index: n } });
752
+ parent.notify('freehand-draw', { prop: 'hoverFhd', onPropertyChange: false,
753
+ value: { strokeColor: null, strokeWidth: null } });
754
+ upperCanvas.style.cursor = parent.cursor = 'pointer';
755
+ isEntered = true;
756
+ break;
757
+ }
758
+ else if (!this.isFhdEditing || parent.pointColl[n].isSelected) {
759
+ if (this.isFhdPoint || this.isFhdEditing) {
760
+ upperContext.clearRect(0, 0, upperCanvas.width, upperCanvas.height);
761
+ if (parent.activeObj.shape && textArea.style.display === 'none') {
762
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'duplicate', obj: parent.activeObj } });
763
+ }
764
+ }
765
+ if (this.isFhdEditing) {
766
+ var strokeColor = parent.pointColl[n].strokeColor;
767
+ parent.notify('freehand-draw', { prop: 'hoverFhd', onPropertyChange: false,
768
+ value: { strokeColor: strokeColor, strokeWidth: parent.pointColl[n].strokeWidth } });
769
+ }
770
+ else {
771
+ parent.notify('freehand-draw', { prop: 'setFreehandDrawHoveredIndex', onPropertyChange: false,
772
+ value: { index: null } });
773
+ }
774
+ this.isFhdPoint = false;
775
+ }
776
+ }
777
+ else {
778
+ if (x > parent.points[l].x - parent.pointColl[n].strokeWidth &&
779
+ x < parent.points[l].x + parent.pointColl[n].strokeWidth &&
780
+ y > parent.points[l].y - parent.pointColl[n].strokeWidth &&
781
+ y < parent.points[l].y + parent.pointColl[n].strokeWidth) {
782
+ this.isFhdPoint = true;
783
+ parent.notify('freehand-draw', { prop: 'setFreehandDrawHoveredIndex', onPropertyChange: false,
784
+ value: { index: n } });
785
+ parent.notify('freehand-draw', { prop: 'hoverFhd', onPropertyChange: false,
786
+ value: { strokeColor: null, strokeWidth: null } });
787
+ upperCanvas.style.cursor = parent.cursor = 'pointer';
788
+ isEntered = true;
789
+ break;
790
+ }
791
+ else if (!this.isFhdEditing || parent.pointColl[n].isSelected) {
792
+ if (this.isFhdPoint || this.isFhdEditing) {
793
+ upperContext.clearRect(0, 0, upperCanvas.width, upperCanvas.height);
794
+ if (parent.activeObj.shape && textArea.style.display === 'none') {
795
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'duplicate', obj: parent.activeObj } });
796
+ }
797
+ }
798
+ if (this.isFhdEditing) {
799
+ var strokeColor = parent.pointColl[n].strokeColor;
800
+ parent.notify('freehand-draw', { prop: 'hoverFhd', onPropertyChange: false,
801
+ value: { strokeColor: strokeColor, strokeWidth: parent.pointColl[n].strokeWidth } });
802
+ }
803
+ this.isFhdPoint = false;
804
+ }
805
+ }
806
+ }
807
+ if (isEntered) {
808
+ break;
809
+ }
810
+ }
811
+ };
812
+ Selection.prototype.setCursorFromObj = function (x, y, obj, upperCanvas, isCropSelection) {
813
+ var parent = this.parent;
814
+ for (var i = 0, len = obj.length; i < len; i++) {
815
+ if (parent.cursor === 'move') {
816
+ return;
817
+ }
818
+ var actObj = extend({}, obj[i], {}, true);
819
+ this.cursorTargetId = actObj.currIndex;
820
+ if (actObj.shape === 'line' || actObj.shape === 'arrow') {
821
+ this.setCursorForLineArrow(actObj, x, y, upperCanvas);
822
+ }
823
+ else if (actObj.shape === 'path') {
824
+ this.setCursorForPath(actObj, x, y, upperCanvas);
825
+ }
826
+ else if (!isNullOrUndefined(actObj.rotatedAngle) && actObj.rotatedAngle !== 0) {
827
+ this.setCursorForRotatedObject(actObj, x, y, upperCanvas);
828
+ }
829
+ else {
830
+ upperCanvas.style.cursor = parent.cursor = this.getMouseCursor(actObj, x, y, isCropSelection, true);
831
+ }
832
+ }
833
+ };
834
+ Selection.prototype.isInside = function (x, y, z1, z2, z3, z4) {
835
+ var x1 = Math.min(z1, z3);
836
+ var x2 = Math.max(z1, z3);
837
+ var y1 = Math.min(z2, z4);
838
+ var y2 = Math.max(z2, z4);
839
+ if ((x1 <= x && x <= x2) && (y1 <= y && y <= y2)) {
840
+ return true;
841
+ }
842
+ else {
843
+ return false;
844
+ }
845
+ };
846
+ Selection.prototype.updateActivePoint = function (x, y, isCropSelection) {
847
+ var parent = this.parent;
848
+ var obj = { width: 0, height: 0 };
849
+ parent.notify('transform', { prop: 'calcMaxDimension', onPropertyChange: false,
850
+ value: { width: parent.activeObj.activePoint.width, height: parent.activeObj.activePoint.height, obj: obj } });
851
+ var maxDimension = obj;
852
+ var previousShapeSettings = this.updatePrevShapeSettings();
853
+ var shapeResizingArgs = { action: 'resize', previousShapeSettings: previousShapeSettings };
854
+ var shapeMovingArgs = { action: 'move', previousShapeSettings: previousShapeSettings };
855
+ if (isNullOrUndefined(this.shapeResizingArgs)) {
856
+ this.shapeResizingArgs = shapeResizingArgs;
857
+ }
858
+ if (isNullOrUndefined(this.shapeMovingArgs)) {
859
+ this.shapeMovingArgs = shapeMovingArgs;
860
+ }
861
+ if (parent.activeObj.shape === 'text' && this.dragElement !== '') {
862
+ parent.notify('shape', { prop: 'updateFontRatio', onPropertyChange: false,
863
+ value: { obj: parent.activeObj, isTextArea: null } });
864
+ }
865
+ if (this.currentDrawingShape !== '' && (this.dragElement === '' || this.dragElement === 'move')) {
866
+ if (parent.activeObj.shape === 'line' || parent.activeObj.shape === 'arrow' ||
867
+ parent.activeObj.shape === 'path') {
868
+ this.dragElement = 'e-resize';
869
+ }
870
+ else {
871
+ if (x > parent.activeObj.activePoint.startX && y > parent.activeObj.activePoint.startY) {
872
+ this.dragElement = 'se-resize';
873
+ }
874
+ else if (x < parent.activeObj.activePoint.startX && y > parent.activeObj.activePoint.startY) {
875
+ this.dragElement = 'sw-resize';
876
+ }
877
+ else if (x > parent.activeObj.activePoint.startX && y < parent.activeObj.activePoint.startY) {
878
+ this.dragElement = 'ne-resize';
879
+ }
880
+ else if (x < parent.activeObj.activePoint.startX && y < parent.activeObj.activePoint.startY) {
881
+ this.dragElement = 'nw-resize';
882
+ }
883
+ }
884
+ }
885
+ if (parent.activeObj.shape === 'arrow') {
886
+ if (Math.atan2(x - parent.lowerCanvas.width / 2, y - parent.lowerCanvas.height / 2) > 0) {
887
+ parent.activeObj.rotatedAngle = -Math.atan2(x - parent.lowerCanvas.width / 2, y - parent.lowerCanvas.height / 2);
888
+ }
889
+ else {
890
+ parent.activeObj.rotatedAngle = Math.abs(Math.atan2(x - parent.lowerCanvas.width / 2, y - parent.lowerCanvas.height / 2));
891
+ }
892
+ }
893
+ var degree;
894
+ var isHorizontalflip = false;
895
+ var isVerticalflip = false;
896
+ switch (this.dragElement.toLowerCase()) {
897
+ case 'nw-resize':
898
+ this.updateNWPoints(x, y, maxDimension);
899
+ parent.notify('shape', { prop: 'updateArrowDirection', onPropertyChange: false,
900
+ value: { obj: parent.activeObj, flip: null, rotatedDegree: null } });
901
+ this.triggerShapeChange(shapeResizingArgs, shapeMovingArgs, 'resize');
902
+ break;
903
+ case 'n-resize':
904
+ this.updateNPoints(x, y);
905
+ parent.notify('shape', { prop: 'updateArrowDirection', onPropertyChange: false,
906
+ value: { obj: parent.activeObj, flip: null, rotatedDegree: null } });
907
+ this.triggerShapeChange(shapeResizingArgs, shapeMovingArgs, 'resize');
908
+ break;
909
+ case 'ne-resize':
910
+ this.updateNEPoints(x, y, maxDimension);
911
+ parent.notify('shape', { prop: 'updateArrowDirection', onPropertyChange: false,
912
+ value: { obj: parent.activeObj, flip: null, rotatedDegree: null } });
913
+ this.triggerShapeChange(shapeResizingArgs, shapeMovingArgs, 'resize');
914
+ break;
915
+ case 'w-resize':
916
+ this.updateWPoints(x, y);
917
+ parent.notify('shape', { prop: 'updateArrowDirection', onPropertyChange: false,
918
+ value: { obj: parent.activeObj, flip: null, rotatedDegree: null } });
919
+ this.triggerShapeChange(shapeResizingArgs, shapeMovingArgs, 'resize');
920
+ break;
921
+ case 'e-resize':
922
+ this.updateEPoints(x, y);
923
+ parent.notify('shape', { prop: 'updateArrowDirection', onPropertyChange: false,
924
+ value: { obj: parent.activeObj, flip: null, rotatedDegree: null } });
925
+ this.triggerShapeChange(shapeResizingArgs, shapeMovingArgs, 'resize');
926
+ break;
927
+ case 'sw-resize':
928
+ this.updateSWPoints(x, y, maxDimension);
929
+ parent.notify('shape', { prop: 'updateArrowDirection', onPropertyChange: false,
930
+ value: { obj: parent.activeObj, flip: null, rotatedDegree: null } });
931
+ this.triggerShapeChange(shapeResizingArgs, shapeMovingArgs, 'resize');
932
+ break;
933
+ case 's-resize':
934
+ this.updateSPoints(x, y);
935
+ parent.notify('shape', { prop: 'updateArrowDirection', onPropertyChange: false,
936
+ value: { obj: parent.activeObj, flip: null, rotatedDegree: null } });
937
+ this.triggerShapeChange(shapeResizingArgs, shapeMovingArgs, 'resize');
938
+ break;
939
+ case 'se-resize':
940
+ this.updateSEPoints(x, y, maxDimension);
941
+ parent.notify('shape', { prop: 'updateArrowDirection', onPropertyChange: false,
942
+ value: { obj: parent.activeObj, flip: null, rotatedDegree: null } });
943
+ this.triggerShapeChange(shapeResizingArgs, shapeMovingArgs, 'resize');
944
+ break;
945
+ case 'grabbing':
946
+ if (Math.atan2(x - (parent.activeObj.activePoint.startX + (parent.activeObj.activePoint.width / 2)), y - (parent.activeObj.activePoint.startY + (parent.activeObj.activePoint.height / 2))) > 0) {
947
+ parent.activeObj.rotatedAngle = -Math.atan2(x - (parent.activeObj.activePoint.startX + (parent.activeObj.activePoint.width
948
+ / 2)), y - (parent.activeObj.activePoint.startY + (parent.activeObj.activePoint.height / 2)));
949
+ }
950
+ else {
951
+ parent.activeObj.rotatedAngle = Math.abs(Math.atan2(x - (parent.activeObj.activePoint.startX +
952
+ (parent.activeObj.activePoint.width / 2)), y - (parent.activeObj.activePoint.startY +
953
+ (parent.activeObj.activePoint.height / 2))));
954
+ }
955
+ if (parent.activeObj.shapeDegree === 0) {
956
+ degree = parent.transform.degree;
957
+ }
958
+ else {
959
+ degree = parent.transform.degree - parent.activeObj.shapeDegree;
960
+ }
961
+ if (degree < 0) {
962
+ degree = 360 + degree;
963
+ }
964
+ for (var i = 0, len = parent.activeObj.flipObjColl.length; i < len; i++) {
965
+ if (parent.activeObj.flipObjColl[i].toLowerCase() === 'horizontal') {
966
+ isHorizontalflip = true;
967
+ }
968
+ else if (parent.activeObj.flipObjColl[i].toLowerCase() === 'vertical') {
969
+ isVerticalflip = true;
970
+ }
971
+ }
972
+ parent.activeObj.rotatedAngle -= (degree * (Math.PI / 180));
973
+ if (degree === 0 || degree === 360) {
974
+ if (isVerticalflip) {
975
+ parent.activeObj.rotatedAngle -= (180 * (Math.PI / 180));
976
+ }
977
+ }
978
+ else if (degree === 90 || degree === -270) {
979
+ if (isHorizontalflip) {
980
+ parent.activeObj.rotatedAngle -= (180 * (Math.PI / 180));
981
+ }
982
+ }
983
+ else if (degree === 180 || degree === -180) {
984
+ if (isVerticalflip) {
985
+ parent.activeObj.rotatedAngle -= (180 * (Math.PI / 180));
986
+ }
987
+ }
988
+ else if (degree === 270 || degree === -90) {
989
+ if (isHorizontalflip) {
990
+ parent.activeObj.rotatedAngle -= (180 * (Math.PI / 180));
991
+ }
992
+ }
993
+ break;
994
+ case 'pathdrag':
995
+ if (!isNullOrUndefined(this.pathAdjustedIndex)) {
996
+ parent.activeObj.pointColl[this.pathAdjustedIndex].x = x;
997
+ parent.activeObj.pointColl[this.pathAdjustedIndex].y = y;
998
+ }
999
+ break;
1000
+ default:
1001
+ if (!isCropSelection && !parent.currObjType.isCustomCrop) {
1002
+ if (this.dragPoint.startX) {
1003
+ var width = (this.dragPoint.endX - this.previousPoint.x);
1004
+ var height = (this.dragPoint.endY - this.previousPoint.y);
1005
+ parent.activeObj.activePoint.startX += width;
1006
+ parent.activeObj.activePoint.endX += width;
1007
+ parent.activeObj.activePoint.startY += height;
1008
+ parent.activeObj.activePoint.endY += height;
1009
+ if (parent.activeObj.shape !== 'line' && parent.activeObj.shape !== 'arrow' &&
1010
+ parent.activeObj.rotationCirclePointColl) {
1011
+ parent.activeObj.rotationCirclePointColl.x += width;
1012
+ parent.activeObj.rotationCirclePointColl.y += height;
1013
+ parent.activeObj.rotationCirclePoint.x += width;
1014
+ parent.activeObj.rotationCirclePoint.y += height;
1015
+ }
1016
+ if (parent.activeObj.shape === 'path') {
1017
+ for (var i = 0, len = parent.activeObj.pointColl.length; i < len; i++) {
1018
+ parent.activeObj.pointColl[i].x += width;
1019
+ parent.activeObj.pointColl[i].y += height;
1020
+ }
1021
+ }
1022
+ if (!this.isPreventDragging && (parent.activeObj.activePoint.startX < parent.img.destLeft ||
1023
+ parent.activeObj.activePoint.startY < parent.img.destTop || parent.activeObj.activePoint.endX >
1024
+ parent.img.destLeft + parent.img.destWidth || parent.activeObj.activePoint.endY > parent.img.destTop
1025
+ + parent.img.destHeight)) {
1026
+ parent.activeObj.activePoint.startX -= width;
1027
+ parent.activeObj.activePoint.endX -= width;
1028
+ parent.activeObj.activePoint.startY -= height;
1029
+ parent.activeObj.activePoint.endY -= height;
1030
+ if (parent.activeObj.shape !== 'line' && parent.activeObj.shape !== 'arrow' &&
1031
+ parent.activeObj.rotationCirclePointColl) {
1032
+ parent.activeObj.rotationCirclePointColl.x -= width;
1033
+ parent.activeObj.rotationCirclePointColl.y -= height;
1034
+ parent.activeObj.rotationCirclePoint.x -= width;
1035
+ parent.activeObj.rotationCirclePoint.y -= height;
1036
+ }
1037
+ this.setDragWidth(width);
1038
+ this.setDragHeight(height);
1039
+ }
1040
+ }
1041
+ else {
1042
+ parent.activeObj.activePoint.startX = x < this.mouseDownPoint.x ? x : this.mouseDownPoint.x;
1043
+ parent.activeObj.activePoint.startY = y < this.mouseDownPoint.y ? y : this.mouseDownPoint.y;
1044
+ x = x < this.mouseDownPoint.x ? this.mouseDownPoint.x : x;
1045
+ y = y < this.mouseDownPoint.y ? this.mouseDownPoint.y : y;
1046
+ parent.activeObj.activePoint.endX = x;
1047
+ parent.activeObj.activePoint.endY = y;
1048
+ }
1049
+ this.triggerShapeChange(shapeResizingArgs, shapeMovingArgs, 'move');
1050
+ }
1051
+ break;
1052
+ }
1053
+ };
1054
+ Selection.prototype.triggerShapeChange = function (shapeResizingArgs, shapeMovingArgs, type) {
1055
+ var parent = this.parent;
1056
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
1057
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1058
+ var currentShapeSettings = this.updatePrevShapeSettings();
1059
+ shapeResizingArgs.currentShapeSettings = currentShapeSettings;
1060
+ shapeMovingArgs.currentShapeSettings = currentShapeSettings;
1061
+ if (type === 'resize') {
1062
+ this.isCropSelection = false;
1063
+ var splitWords = void 0;
1064
+ if (parent.activeObj.shape !== undefined) {
1065
+ splitWords = parent.activeObj.shape.split('-');
1066
+ }
1067
+ if (splitWords !== undefined && splitWords[0] === 'crop') {
1068
+ this.isCropSelection = true;
1069
+ }
1070
+ if (!this.isCropSelection && this.parent.eventType !== 'resize' && isBlazor() && parent.events && this.parent.events.onShapeResizeStart.hasDelegate === true) {
1071
+ shapeResizingArgs.action = 'resize-start';
1072
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
1073
+ parent.dotNetRef.invokeMethodAsync('ShapeEventAsync', 'OnShapeResizeStart', shapeResizingArgs).then(function (shapeResizingArgs) {
1074
+ parent.notify('shape', { prop: 'updateShapeChangeEventArgs', onPropertyChange: false,
1075
+ value: { shapeSettings: shapeResizingArgs.currentShapeSettings } });
1076
+ });
1077
+ }
1078
+ else if (!this.isCropSelection) {
1079
+ parent.trigger('shapeChanging', shapeResizingArgs);
1080
+ parent.notify('shape', { prop: 'updateShapeChangeEventArgs', onPropertyChange: false,
1081
+ value: { shapeSettings: shapeResizingArgs.currentShapeSettings } });
1082
+ }
1083
+ else {
1084
+ var selectionResizingArgs = { action: shapeResizingArgs.action,
1085
+ previousSelectionSettings: { type: parent.getSelectionType(parent.activeObj.shape),
1086
+ startX: shapeResizingArgs.previousShapeSettings.startX,
1087
+ startY: shapeResizingArgs.previousShapeSettings.startY,
1088
+ width: shapeResizingArgs.previousShapeSettings.width,
1089
+ height: shapeResizingArgs.previousShapeSettings.height },
1090
+ currentSelectionSettings: { type: parent.getSelectionType(parent.activeObj.shape),
1091
+ startX: shapeResizingArgs.currentShapeSettings.startX,
1092
+ startY: shapeResizingArgs.currentShapeSettings.startY,
1093
+ width: shapeResizingArgs.currentShapeSettings.width,
1094
+ height: shapeResizingArgs.currentShapeSettings.height } };
1095
+ if (isNullOrUndefined(this.selectionResizingArgs)) {
1096
+ this.selectionResizingArgs = selectionResizingArgs;
1097
+ }
1098
+ if (isBlazor() && isNullOrUndefined(this.parent.eventType) && parent.events &&
1099
+ parent.events.onSelectionResizeStart.hasDelegate === true) {
1100
+ selectionResizingArgs.action = 'resize-start';
1101
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
1102
+ parent.dotNetRef.invokeMethodAsync('SelectionEventAsync', 'OnSelectionResizeStart', selectionResizingArgs).then(function (selectionResizingArgs) {
1103
+ parent.notify('shape', { prop: 'updSelChangeEventArgs', onPropertyChange: false,
1104
+ value: { selectionSettings: selectionResizingArgs.currentSelectionSettings } });
1105
+ });
1106
+ }
1107
+ else {
1108
+ parent.trigger('selectionChanging', selectionResizingArgs);
1109
+ parent.notify('shape', { prop: 'updSelChangeEventArgs', onPropertyChange: false,
1110
+ value: { selectionSettings: selectionResizingArgs.currentSelectionSettings } });
1111
+ }
1112
+ }
1113
+ }
1114
+ else {
1115
+ if (isBlazor() && isNullOrUndefined(this.parent.eventType) && parent.events &&
1116
+ parent.events.onShapeDragStart.hasDelegate === true) {
1117
+ shapeMovingArgs.action = 'drag-start';
1118
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
1119
+ parent.dotNetRef.invokeMethodAsync('ShapeEventAsync', 'OnShapeDragStart', shapeMovingArgs).then(function (shapeMovingArgs) {
1120
+ parent.notify('shape', { prop: 'updateShapeChangeEventArgs', onPropertyChange: false,
1121
+ value: { shapeSettings: shapeMovingArgs.currentShapeSettings } });
1122
+ });
1123
+ }
1124
+ else {
1125
+ parent.trigger('shapeChanging', shapeMovingArgs);
1126
+ parent.notify('shape', { prop: 'updateShapeChangeEventArgs', onPropertyChange: false,
1127
+ value: { shapeSettings: shapeMovingArgs.currentShapeSettings } });
1128
+ }
1129
+ }
1130
+ this.parent.eventType = type;
1131
+ };
1132
+ Selection.prototype.setDragWidth = function (width) {
1133
+ var parent = this.parent;
1134
+ var tempWidth = width;
1135
+ if (tempWidth >= 0) {
1136
+ for (var i = 0; i < tempWidth; i++) {
1137
+ width = tempWidth - i;
1138
+ parent.activeObj.activePoint.startX += width;
1139
+ parent.activeObj.activePoint.endX += width;
1140
+ if (parent.activeObj.activePoint.startX >= parent.img.destLeft &&
1141
+ parent.activeObj.activePoint.endX <= parent.img.destLeft + parent.img.destWidth) {
1142
+ break;
1143
+ }
1144
+ else {
1145
+ parent.activeObj.activePoint.startX -= width;
1146
+ parent.activeObj.activePoint.endX -= width;
1147
+ }
1148
+ }
1149
+ }
1150
+ else {
1151
+ for (var i = 1; i < Math.abs(tempWidth); i++) {
1152
+ width = tempWidth + i;
1153
+ parent.activeObj.activePoint.startX += width;
1154
+ parent.activeObj.activePoint.endX += width;
1155
+ if (parent.activeObj.activePoint.startX >= parent.img.destLeft &&
1156
+ parent.activeObj.activePoint.endX <= parent.img.destLeft + parent.img.destWidth) {
1157
+ break;
1158
+ }
1159
+ else {
1160
+ parent.activeObj.activePoint.startX -= width;
1161
+ parent.activeObj.activePoint.endX -= width;
1162
+ }
1163
+ }
1164
+ }
1165
+ };
1166
+ Selection.prototype.setDragHeight = function (height) {
1167
+ var parent = this.parent;
1168
+ var tempHeight = height;
1169
+ if (tempHeight >= 0) {
1170
+ for (var i = 1; i < tempHeight; i++) {
1171
+ height = tempHeight - i;
1172
+ parent.activeObj.activePoint.startY += height;
1173
+ parent.activeObj.activePoint.endY += height;
1174
+ if (parent.activeObj.activePoint.startY >= parent.img.destTop &&
1175
+ parent.activeObj.activePoint.endY <= parent.img.destTop + parent.img.destHeight) {
1176
+ break;
1177
+ }
1178
+ else {
1179
+ parent.activeObj.activePoint.startY -= height;
1180
+ parent.activeObj.activePoint.endY -= height;
1181
+ }
1182
+ }
1183
+ }
1184
+ else {
1185
+ for (var i = 0; i < Math.abs(tempHeight); i++) {
1186
+ height = tempHeight + i;
1187
+ parent.activeObj.activePoint.startY += height;
1188
+ parent.activeObj.activePoint.endY += height;
1189
+ if (parent.activeObj.activePoint.startY >= parent.img.destTop &&
1190
+ parent.activeObj.activePoint.endY <= parent.img.destTop + parent.img.destHeight) {
1191
+ break;
1192
+ }
1193
+ else {
1194
+ parent.activeObj.activePoint.startY -= height;
1195
+ parent.activeObj.activePoint.endY -= height;
1196
+ }
1197
+ }
1198
+ }
1199
+ };
1200
+ Selection.prototype.limitDrag = function (isStart) {
1201
+ var parent = this.parent;
1202
+ var startX = isStart ? parent.activeObj.activePoint.startX : parent.activeObj.activePoint.endX;
1203
+ var startY = isStart ? parent.activeObj.activePoint.startY : parent.activeObj.activePoint.endY;
1204
+ var endX = isStart ? parent.activeObj.activePoint.endX : parent.activeObj.activePoint.startX;
1205
+ var endY = isStart ? parent.activeObj.activePoint.endY : parent.activeObj.activePoint.startY;
1206
+ if (startX < parent.img.destLeft) {
1207
+ startX = parent.img.destLeft;
1208
+ }
1209
+ if (startY < parent.img.destTop) {
1210
+ startY = parent.img.destTop;
1211
+ }
1212
+ if (endX > parent.img.destLeft + parent.img.destWidth) {
1213
+ endX = parent.img.destLeft + parent.img.destWidth;
1214
+ }
1215
+ if (endY > parent.img.destTop + parent.img.destHeight) {
1216
+ endY = parent.img.destTop + parent.img.destHeight;
1217
+ }
1218
+ if (isStart) {
1219
+ parent.activeObj.activePoint.startX = startX;
1220
+ parent.activeObj.activePoint.startY = startY;
1221
+ parent.activeObj.activePoint.endX = endX;
1222
+ parent.activeObj.activePoint.endY = endY;
1223
+ }
1224
+ else {
1225
+ parent.activeObj.activePoint.startX = endX;
1226
+ parent.activeObj.activePoint.startY = endY;
1227
+ parent.activeObj.activePoint.endX = startX;
1228
+ parent.activeObj.activePoint.endY = startY;
1229
+ }
1230
+ };
1231
+ Selection.prototype.preventDraggingInvertly = function () {
1232
+ var parent = this.parent;
1233
+ if (!this.isPreventDragging && parent.activeObj.rotatedAngle === 0) {
1234
+ this.limitDrag(true);
1235
+ if (parent.activeObj.shape === 'line' || parent.activeObj.shape === 'arrow' ||
1236
+ parent.activeObj.shape === 'path') {
1237
+ this.limitDrag(false);
1238
+ }
1239
+ }
1240
+ };
1241
+ Selection.prototype.preventTextDraggingInvertly = function () {
1242
+ var parent = this.parent;
1243
+ var isLimiting = false;
1244
+ if (!this.isPreventDragging) {
1245
+ if (parent.activeObj.activePoint.startX < parent.img.destLeft ||
1246
+ parent.activeObj.activePoint.startY < parent.img.destTop ||
1247
+ parent.activeObj.activePoint.endX > parent.img.destLeft + parent.img.destWidth ||
1248
+ parent.activeObj.activePoint.endY > parent.img.destTop + parent.img.destHeight) {
1249
+ isLimiting = true;
1250
+ }
1251
+ }
1252
+ return isLimiting;
1253
+ };
1254
+ Selection.prototype.preventInverseResize = function (tempActiveObj) {
1255
+ var parent = this.parent;
1256
+ if (parent.activeObj.activePoint.width < 0) {
1257
+ parent.activeObj.activePoint.width = 0;
1258
+ parent.activeObj.activePoint.startX = tempActiveObj.activePoint.startX;
1259
+ parent.activeObj.activePoint.endX = tempActiveObj.activePoint.endX;
1260
+ }
1261
+ if (parent.activeObj.activePoint.height < 0) {
1262
+ parent.activeObj.activePoint.height = 0;
1263
+ parent.activeObj.activePoint.startY = tempActiveObj.activePoint.startY;
1264
+ parent.activeObj.activePoint.endY = tempActiveObj.activePoint.endY;
1265
+ }
1266
+ };
1267
+ Selection.prototype.getScaleRatio = function (scale) {
1268
+ var parent = this.parent;
1269
+ var point = { x: scale, y: scale };
1270
+ if (parent.activeObj.shape && parent.activeObj.shape !== 'crop-custom' &&
1271
+ parent.activeObj.shape !== 'crop-circle' && parent.activeObj.shape !== 'crop-square') {
1272
+ var ratio = parent.activeObj.shape.split('-');
1273
+ if (ratio.length > 1) {
1274
+ ratio = ratio[1].split(':');
1275
+ var newScale = scale / (parseInt(ratio[1], 10));
1276
+ point.x = newScale * (parseInt(ratio[0], 10));
1277
+ point.y = newScale * (parseInt(ratio[1], 10));
1278
+ }
1279
+ }
1280
+ return point;
1281
+ };
1282
+ Selection.prototype.updateNWPoints = function (x, y, maxDimension) {
1283
+ var parent = this.parent;
1284
+ var diff;
1285
+ var width;
1286
+ var height;
1287
+ var scale;
1288
+ var percentage;
1289
+ var prevDiffX = this.diffPoint.x;
1290
+ var prevDiffY = this.diffPoint.y;
1291
+ var tempActiveObj = extend({}, parent.activeObj, null, true);
1292
+ if (parent.activeObj.shape === 'text') {
1293
+ if (this.oldPoint.x === undefined && this.oldPoint.y === undefined) {
1294
+ this.diffPoint.x = parent.activeObj.activePoint.startX - x;
1295
+ this.diffPoint.y = parent.activeObj.activePoint.startY - y;
1296
+ }
1297
+ else {
1298
+ this.diffPoint.x = this.oldPoint.x - x;
1299
+ this.diffPoint.y = this.oldPoint.y - y;
1300
+ }
1301
+ this.oldPoint.x = x;
1302
+ this.oldPoint.y = y;
1303
+ if (this.diffPoint.x <= prevDiffX && this.diffPoint.y >= prevDiffY) {
1304
+ diff = Math.min(this.diffPoint.x, this.diffPoint.y);
1305
+ }
1306
+ else {
1307
+ diff = Math.max(this.diffPoint.x, this.diffPoint.y);
1308
+ }
1309
+ percentage = (diff / 10);
1310
+ parent.activeObj.activePoint.startX -= (maxDimension.width / 100) * percentage;
1311
+ parent.activeObj.activePoint.startY -= (maxDimension.height / 100) * percentage;
1312
+ if (this.preventTextDraggingInvertly()) {
1313
+ parent.activeObj.activePoint.startX += (maxDimension.width / 100) * percentage;
1314
+ parent.activeObj.activePoint.startY += (maxDimension.height / 100) * percentage;
1315
+ }
1316
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
1317
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1318
+ parent.notify('shape', { prop: 'updateFontSize', onPropertyChange: false,
1319
+ value: { obj: parent.activeObj } });
1320
+ }
1321
+ else {
1322
+ var splitWords = void 0;
1323
+ if (parent.activeObj.shape !== undefined) {
1324
+ splitWords = parent.activeObj.shape.split('-');
1325
+ }
1326
+ if (parent.activeObj.shape === 'crop-custom' || (parent.activeObj.shape !== undefined && splitWords[0] !== 'crop')) {
1327
+ this.adjustNWPoints(parent.activeObj.activePoint, x, y, parent.activeObj.rotatedAngle);
1328
+ if (parent.activeObj.activePoint.startX > parent.activeObj.activePoint.endX) {
1329
+ var temp = parent.activeObj.activePoint.startX;
1330
+ parent.activeObj.activePoint.startX = parent.activeObj.activePoint.endX;
1331
+ parent.activeObj.activePoint.endX = temp;
1332
+ this.dragElement = parent.upperCanvas.style.cursor = parent.cursor = 'ne-resize';
1333
+ }
1334
+ if (parent.activeObj.activePoint.startY > parent.activeObj.activePoint.endY) {
1335
+ var temp = parent.activeObj.activePoint.startY;
1336
+ parent.activeObj.activePoint.startY = parent.activeObj.activePoint.endY;
1337
+ parent.activeObj.activePoint.endY = temp;
1338
+ this.dragElement = parent.upperCanvas.style.cursor = parent.cursor = 'sw-resize';
1339
+ }
1340
+ this.preventDraggingInvertly();
1341
+ }
1342
+ else {
1343
+ if (parent.activeObj.activePoint.startX < x && parent.activeObj.activePoint.startY < y) {
1344
+ width = x - parent.activeObj.activePoint.startX;
1345
+ height = y - parent.activeObj.activePoint.startY;
1346
+ scale = Math.min(width, height);
1347
+ var newScale = this.getScaleRatio(scale);
1348
+ parent.activeObj.activePoint.startX += newScale.x;
1349
+ parent.activeObj.activePoint.startY += newScale.y;
1350
+ var left = parent.img.destLeft > 0 ? parent.img.destLeft : 0;
1351
+ var top_1 = parent.img.destTop > 0 ? parent.img.destTop : 0;
1352
+ if (parent.activeObj.activePoint.startX < left || parent.activeObj.activePoint.startY < top_1) {
1353
+ parent.activeObj.activePoint.startX -= newScale.x;
1354
+ parent.activeObj.activePoint.startY -= newScale.y;
1355
+ }
1356
+ }
1357
+ else {
1358
+ width = parent.activeObj.activePoint.startX - x;
1359
+ height = y - parent.activeObj.activePoint.endY;
1360
+ scale = Math.max(width, height);
1361
+ var newScale = this.getScaleRatio(scale);
1362
+ parent.activeObj.activePoint.startX -= newScale.x;
1363
+ parent.activeObj.activePoint.startY -= newScale.y;
1364
+ var left = parent.img.destLeft > 0 ? parent.img.destLeft : 0;
1365
+ var top_2 = parent.img.destTop > 0 ? parent.img.destTop : 0;
1366
+ if (parent.activeObj.activePoint.startX < left || parent.activeObj.activePoint.startY < top_2) {
1367
+ parent.activeObj.activePoint.startX += newScale.x;
1368
+ parent.activeObj.activePoint.startY += newScale.y;
1369
+ }
1370
+ }
1371
+ }
1372
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
1373
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1374
+ this.preventInverseResize(tempActiveObj);
1375
+ }
1376
+ };
1377
+ Selection.prototype.updateNPoints = function (x, y) {
1378
+ var parent = this.parent;
1379
+ var width;
1380
+ var height;
1381
+ var scale;
1382
+ if (parent.activeObj.shape !== 'text') {
1383
+ var splitWords = void 0;
1384
+ if (parent.activeObj.shape) {
1385
+ splitWords = parent.activeObj.shape.split('-');
1386
+ }
1387
+ if (parent.activeObj.shape === 'crop-custom' || (parent.activeObj.shape && splitWords[0] !== 'crop')) {
1388
+ if (parent.activeObj.shape !== 'line' && parent.activeObj.shape !== 'arrow' && parent.activeObj.shape !== 'path' &&
1389
+ parent.activeObj.rotatedAngle !== 0 && this.dragPoint.startX) {
1390
+ if (this.dragPoint.startX && this.dragPoint.startY) {
1391
+ this.previousPoint.x = this.dragPoint.endX;
1392
+ this.previousPoint.y = this.dragPoint.endY;
1393
+ this.dragPoint.endX = x;
1394
+ this.dragPoint.endY = y;
1395
+ }
1396
+ width = (this.dragPoint.endX - this.previousPoint.x);
1397
+ height = (this.dragPoint.endY - this.previousPoint.y);
1398
+ this.adjustRotationPoints(parent.activeObj.activePoint, width, height, parent.activeObj.rotatedAngle);
1399
+ }
1400
+ else {
1401
+ parent.activeObj.activePoint.startY = y;
1402
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1403
+ }
1404
+ if (parent.activeObj.activePoint.startY > parent.activeObj.activePoint.endY) {
1405
+ var temp = parent.activeObj.activePoint.startY;
1406
+ parent.activeObj.activePoint.startY = parent.activeObj.activePoint.endY;
1407
+ parent.activeObj.activePoint.endY = temp;
1408
+ this.dragElement = this.resizedElement = 's-resize';
1409
+ }
1410
+ this.preventDraggingInvertly();
1411
+ }
1412
+ else {
1413
+ if (parent.activeObj.activePoint.endX > x && parent.activeObj.activePoint.startY < y) {
1414
+ width = parent.activeObj.activePoint.endX - x;
1415
+ height = y - parent.activeObj.activePoint.startY;
1416
+ scale = Math.min(width, height);
1417
+ var newScale = this.getScaleRatio(scale);
1418
+ parent.activeObj.activePoint.endX -= newScale.x;
1419
+ parent.activeObj.activePoint.startY += newScale.y;
1420
+ if (parent.activeObj.activePoint.endX > (parent.img.destLeft + parent.img.destWidth) ||
1421
+ parent.activeObj.activePoint.startY < parent.img.destTop) {
1422
+ parent.activeObj.activePoint.endX += newScale.x;
1423
+ parent.activeObj.activePoint.startY -= newScale.y;
1424
+ }
1425
+ }
1426
+ else {
1427
+ width = x - parent.activeObj.activePoint.endX;
1428
+ height = parent.activeObj.activePoint.startY - y;
1429
+ scale = Math.max(width, height);
1430
+ var newScale = this.getScaleRatio(scale);
1431
+ parent.activeObj.activePoint.endX += newScale.x;
1432
+ parent.activeObj.activePoint.startY -= newScale.y;
1433
+ if (parent.activeObj.activePoint.endX > (parent.img.destLeft + parent.img.destWidth) ||
1434
+ parent.activeObj.activePoint.startY < parent.img.destTop) {
1435
+ parent.activeObj.activePoint.endX -= newScale.x;
1436
+ parent.activeObj.activePoint.startY += newScale.y;
1437
+ }
1438
+ }
1439
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
1440
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1441
+ }
1442
+ }
1443
+ };
1444
+ Selection.prototype.updateNEPoints = function (x, y, maxDimension) {
1445
+ var parent = this.parent;
1446
+ var diff;
1447
+ var width;
1448
+ var height;
1449
+ var scale;
1450
+ var percentage;
1451
+ var prevDiffX = this.diffPoint.x;
1452
+ var prevDiffY = this.diffPoint.y;
1453
+ var tempActiveObj = extend({}, parent.activeObj, null, true);
1454
+ if (parent.activeObj.shape === 'text') {
1455
+ if (this.oldPoint.x === undefined && this.oldPoint.y === undefined) {
1456
+ this.diffPoint.x = x - parent.activeObj.activePoint.endX;
1457
+ this.diffPoint.y = parent.activeObj.activePoint.startY - y;
1458
+ }
1459
+ else {
1460
+ this.diffPoint.x = x - this.oldPoint.x;
1461
+ this.diffPoint.y = this.oldPoint.y - y;
1462
+ }
1463
+ this.oldPoint.x = x;
1464
+ this.oldPoint.y = y;
1465
+ if (this.diffPoint.x <= prevDiffX && this.diffPoint.y >= prevDiffY) {
1466
+ diff = Math.min(this.diffPoint.x, this.diffPoint.y);
1467
+ }
1468
+ else {
1469
+ diff = Math.max(this.diffPoint.x, this.diffPoint.y);
1470
+ }
1471
+ percentage = (diff / 10);
1472
+ parent.activeObj.activePoint.endX += (maxDimension.width / 100) * percentage;
1473
+ parent.activeObj.activePoint.startY -= (maxDimension.height / 100) * percentage;
1474
+ if (this.preventTextDraggingInvertly()) {
1475
+ parent.activeObj.activePoint.endX -= (maxDimension.width / 100) * percentage;
1476
+ parent.activeObj.activePoint.startY += (maxDimension.height / 100) * percentage;
1477
+ }
1478
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
1479
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1480
+ parent.notify('shape', { prop: 'updateFontSize', onPropertyChange: false,
1481
+ value: { obj: parent.activeObj } });
1482
+ }
1483
+ else {
1484
+ var splitWords = void 0;
1485
+ if (parent.activeObj.shape) {
1486
+ splitWords = parent.activeObj.shape.split('-');
1487
+ }
1488
+ if (parent.activeObj.shape === 'crop-custom' || (parent.activeObj.shape !== undefined && splitWords[0] !== 'crop')) {
1489
+ this.adjustNEPoints(parent.activeObj.activePoint, x, y, parent.activeObj.rotatedAngle);
1490
+ if (parent.activeObj.activePoint.endX < parent.activeObj.activePoint.startX) {
1491
+ var temp = parent.activeObj.activePoint.endX;
1492
+ parent.activeObj.activePoint.endX = parent.activeObj.activePoint.startX;
1493
+ parent.activeObj.activePoint.startX = temp;
1494
+ this.dragElement = parent.upperCanvas.style.cursor = parent.cursor = 'nw-resize';
1495
+ }
1496
+ if (parent.activeObj.activePoint.startY > parent.activeObj.activePoint.endY) {
1497
+ var temp = parent.activeObj.activePoint.startY;
1498
+ parent.activeObj.activePoint.startY = parent.activeObj.activePoint.endY;
1499
+ parent.activeObj.activePoint.endY = temp;
1500
+ this.dragElement = parent.upperCanvas.style.cursor = parent.cursor = 'se-resize';
1501
+ }
1502
+ this.preventDraggingInvertly();
1503
+ }
1504
+ else {
1505
+ if (parent.activeObj.activePoint.endX > x && parent.activeObj.activePoint.startY < y) {
1506
+ width = parent.activeObj.activePoint.endX - x;
1507
+ height = y - parent.activeObj.activePoint.startY;
1508
+ scale = Math.min(width, height);
1509
+ var newScale = this.getScaleRatio(scale);
1510
+ parent.activeObj.activePoint.endX -= newScale.x;
1511
+ parent.activeObj.activePoint.startY += newScale.y;
1512
+ var endX = parent.img.destLeft + parent.img.destWidth < parent.lowerCanvas.width ?
1513
+ parent.img.destLeft + parent.img.destWidth : parent.lowerCanvas.width;
1514
+ var endY = parent.img.destTop > 0 ? parent.img.destTop : 0;
1515
+ if (parent.activeObj.activePoint.endX > endX || parent.activeObj.activePoint.startY < endY) {
1516
+ parent.activeObj.activePoint.endX += newScale.x;
1517
+ parent.activeObj.activePoint.startY -= newScale.y;
1518
+ }
1519
+ }
1520
+ else {
1521
+ width = x - parent.activeObj.activePoint.endX;
1522
+ height = parent.activeObj.activePoint.startY - y;
1523
+ scale = Math.max(width, height);
1524
+ var newScale = this.getScaleRatio(scale);
1525
+ parent.activeObj.activePoint.endX += newScale.x;
1526
+ parent.activeObj.activePoint.startY -= newScale.y;
1527
+ var endX = parent.img.destLeft + parent.img.destWidth < parent.lowerCanvas.width ?
1528
+ parent.img.destLeft + parent.img.destWidth : parent.lowerCanvas.width;
1529
+ var endY = parent.img.destTop > 0 ? parent.img.destTop : 0;
1530
+ if (parent.activeObj.activePoint.endX > endX || parent.activeObj.activePoint.startY < endY) {
1531
+ parent.activeObj.activePoint.endX -= newScale.x;
1532
+ parent.activeObj.activePoint.startY += newScale.y;
1533
+ }
1534
+ }
1535
+ }
1536
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
1537
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1538
+ this.preventInverseResize(tempActiveObj);
1539
+ }
1540
+ };
1541
+ Selection.prototype.updateWPoints = function (x, y) {
1542
+ var parent = this.parent;
1543
+ var width;
1544
+ var height;
1545
+ var scale;
1546
+ if (parent.activeObj.shape !== 'text') {
1547
+ var splitWords = void 0;
1548
+ if (parent.activeObj.shape) {
1549
+ splitWords = parent.activeObj.shape.split('-');
1550
+ }
1551
+ if (parent.activeObj.shape === 'crop-custom' || (parent.activeObj.shape && splitWords[0] !== 'crop')) {
1552
+ if (parent.activeObj.shape !== 'line' && parent.activeObj.shape !== 'arrow' && parent.activeObj.shape !== 'path' &&
1553
+ parent.activeObj.rotatedAngle !== 0 && this.dragPoint.startX) {
1554
+ if (this.dragPoint.startX && this.dragPoint.startY) {
1555
+ this.previousPoint.x = this.dragPoint.endX;
1556
+ this.previousPoint.y = this.dragPoint.endY;
1557
+ this.dragPoint.endX = x;
1558
+ this.dragPoint.endY = y;
1559
+ }
1560
+ width = (this.dragPoint.endX - this.previousPoint.x);
1561
+ height = (this.dragPoint.endY - this.previousPoint.y);
1562
+ this.adjustRotationPoints(parent.activeObj.activePoint, width, height, parent.activeObj.rotatedAngle);
1563
+ }
1564
+ else {
1565
+ parent.activeObj.activePoint.startX = x;
1566
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
1567
+ }
1568
+ if (parent.activeObj.shape === 'line' || parent.activeObj.shape === 'arrow' || parent.activeObj.shape === 'path') {
1569
+ parent.activeObj.activePoint.startY = y;
1570
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1571
+ if (this.adjustActObjForLineArrow()) {
1572
+ this.dragElement = 'e-resize';
1573
+ if (parent.activeObj.triangleDirection === 'right') {
1574
+ parent.activeObj.triangleDirection = 'left';
1575
+ }
1576
+ else if (parent.activeObj.triangleDirection === 'left') {
1577
+ parent.activeObj.triangleDirection = 'right';
1578
+ }
1579
+ }
1580
+ }
1581
+ else if (parent.activeObj.activePoint.startX > parent.activeObj.activePoint.endX) {
1582
+ var temp = parent.activeObj.activePoint.startX;
1583
+ parent.activeObj.activePoint.startX = parent.activeObj.activePoint.endX;
1584
+ parent.activeObj.activePoint.endX = temp;
1585
+ this.dragElement = this.resizedElement = 'e-resize';
1586
+ }
1587
+ this.preventDraggingInvertly();
1588
+ }
1589
+ else {
1590
+ if (parent.activeObj.activePoint.startX < x && parent.activeObj.activePoint.endY > y) {
1591
+ width = x - parent.activeObj.activePoint.startX;
1592
+ height = parent.activeObj.activePoint.endY - y;
1593
+ scale = Math.min(width, height);
1594
+ var newScale = this.getScaleRatio(scale);
1595
+ parent.activeObj.activePoint.startX += newScale.x;
1596
+ parent.activeObj.activePoint.endY -= newScale.y;
1597
+ if (parent.activeObj.activePoint.startX < parent.img.destLeft || parent.activeObj.activePoint.endY >
1598
+ (parent.img.destTop + parent.img.destHeight)) {
1599
+ parent.activeObj.activePoint.startX -= newScale.x;
1600
+ parent.activeObj.activePoint.endY += newScale.y;
1601
+ }
1602
+ }
1603
+ else {
1604
+ width = parent.activeObj.activePoint.startX - x;
1605
+ height = y - parent.activeObj.activePoint.endY;
1606
+ scale = Math.max(width, height);
1607
+ var newScale = this.getScaleRatio(scale);
1608
+ parent.activeObj.activePoint.startX -= newScale.x;
1609
+ parent.activeObj.activePoint.endY += newScale.y;
1610
+ if (parent.activeObj.activePoint.startX < parent.img.destLeft || parent.activeObj.activePoint.endY >
1611
+ (parent.img.destTop + parent.img.destHeight)) {
1612
+ parent.activeObj.activePoint.startX += newScale.x;
1613
+ parent.activeObj.activePoint.endY -= newScale.y;
1614
+ }
1615
+ }
1616
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
1617
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1618
+ }
1619
+ }
1620
+ };
1621
+ Selection.prototype.updateEPoints = function (x, y) {
1622
+ var parent = this.parent;
1623
+ var width;
1624
+ var height;
1625
+ var scale;
1626
+ if (parent.activeObj.shape !== 'text') {
1627
+ var splitWords = void 0;
1628
+ if (parent.activeObj.shape) {
1629
+ splitWords = parent.activeObj.shape.split('-');
1630
+ }
1631
+ if (parent.activeObj.shape === 'crop-custom' || (parent.activeObj.shape && splitWords[0] !== 'crop')) {
1632
+ if (parent.activeObj.shape !== 'line' && parent.activeObj.shape !== 'arrow' && parent.activeObj.shape !== 'path' &&
1633
+ parent.activeObj.rotatedAngle !== 0 && this.dragPoint.startX) {
1634
+ if (this.dragPoint.startX && this.dragPoint.startY) {
1635
+ this.previousPoint.x = this.dragPoint.endX;
1636
+ this.previousPoint.y = this.dragPoint.endY;
1637
+ this.dragPoint.endX = x;
1638
+ this.dragPoint.endY = y;
1639
+ }
1640
+ width = (this.dragPoint.endX - this.previousPoint.x);
1641
+ height = (this.dragPoint.endY - this.previousPoint.y);
1642
+ this.adjustRotationPoints(parent.activeObj.activePoint, width, height, parent.activeObj.rotatedAngle);
1643
+ }
1644
+ else {
1645
+ parent.activeObj.activePoint.endX = x;
1646
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
1647
+ }
1648
+ if (parent.activeObj.shape === 'line' || parent.activeObj.shape === 'arrow' || parent.activeObj.shape === 'path') {
1649
+ parent.activeObj.activePoint.endY = y;
1650
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1651
+ if (this.adjustActObjForLineArrow()) {
1652
+ this.dragElement = 'w-resize';
1653
+ if (parent.activeObj.triangleDirection === 'right') {
1654
+ parent.activeObj.triangleDirection = 'left';
1655
+ }
1656
+ else if (parent.activeObj.triangleDirection === 'left') {
1657
+ parent.activeObj.triangleDirection = 'right';
1658
+ }
1659
+ }
1660
+ }
1661
+ else if (parent.activeObj.activePoint.endX < parent.activeObj.activePoint.startX) {
1662
+ var temp = parent.activeObj.activePoint.endX;
1663
+ parent.activeObj.activePoint.endX = parent.activeObj.activePoint.startX;
1664
+ parent.activeObj.activePoint.startX = temp;
1665
+ this.dragElement = this.resizedElement = 'w-resize';
1666
+ }
1667
+ this.preventDraggingInvertly();
1668
+ }
1669
+ else {
1670
+ if (parent.activeObj.activePoint.endX > x && parent.activeObj.activePoint.endY > y) {
1671
+ width = parent.activeObj.activePoint.endX - x;
1672
+ height = parent.activeObj.activePoint.endY - y;
1673
+ scale = Math.min(width, height);
1674
+ var newScale = this.getScaleRatio(scale);
1675
+ parent.activeObj.activePoint.endX -= newScale.x;
1676
+ parent.activeObj.activePoint.endY -= newScale.y;
1677
+ if (parent.activeObj.activePoint.endX > (parent.img.destLeft + parent.img.destWidth) ||
1678
+ parent.activeObj.activePoint.endY > (parent.img.destTop + parent.img.destHeight)) {
1679
+ parent.activeObj.activePoint.endX += newScale.x;
1680
+ parent.activeObj.activePoint.endY += newScale.y;
1681
+ }
1682
+ }
1683
+ else {
1684
+ width = x - parent.activeObj.activePoint.endX;
1685
+ height = y - parent.activeObj.activePoint.endY;
1686
+ scale = Math.max(width, height);
1687
+ var newScale = this.getScaleRatio(scale);
1688
+ parent.activeObj.activePoint.endX += newScale.x;
1689
+ parent.activeObj.activePoint.endY += newScale.y;
1690
+ if (parent.activeObj.activePoint.endX > (parent.img.destLeft + parent.img.destWidth) ||
1691
+ parent.activeObj.activePoint.endY > (parent.img.destTop + parent.img.destHeight)) {
1692
+ parent.activeObj.activePoint.endX -= newScale.x;
1693
+ parent.activeObj.activePoint.endY -= newScale.y;
1694
+ }
1695
+ }
1696
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
1697
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1698
+ }
1699
+ }
1700
+ };
1701
+ Selection.prototype.updateSWPoints = function (x, y, maxDimension) {
1702
+ var parent = this.parent;
1703
+ var diff;
1704
+ var width;
1705
+ var height;
1706
+ var scale;
1707
+ var percentage;
1708
+ var prevDiffX = this.diffPoint.x;
1709
+ var prevDiffY = this.diffPoint.y;
1710
+ var tempActiveObj = extend({}, parent.activeObj, null, true);
1711
+ if (parent.activeObj.shape === 'text') {
1712
+ if (isNullOrUndefined(this.oldPoint.x) && isNullOrUndefined(this.oldPoint.y)) {
1713
+ this.diffPoint.x = parent.activeObj.activePoint.startX - x;
1714
+ this.diffPoint.y = y - parent.activeObj.activePoint.endY;
1715
+ }
1716
+ else {
1717
+ this.diffPoint.x = this.oldPoint.x - x;
1718
+ this.diffPoint.y = y - this.oldPoint.y;
1719
+ }
1720
+ this.oldPoint.x = x;
1721
+ this.oldPoint.y = y;
1722
+ if (this.diffPoint.x <= prevDiffX && this.diffPoint.y >= prevDiffY) {
1723
+ diff = Math.min(this.diffPoint.x, this.diffPoint.y);
1724
+ }
1725
+ else {
1726
+ diff = Math.max(this.diffPoint.x, this.diffPoint.y);
1727
+ }
1728
+ percentage = (diff / 10);
1729
+ parent.activeObj.activePoint.startX -= (maxDimension.width / 100) * percentage;
1730
+ parent.activeObj.activePoint.endY += (maxDimension.height / 100) * percentage;
1731
+ if (this.preventTextDraggingInvertly()) {
1732
+ parent.activeObj.activePoint.startX += (maxDimension.width / 100) * percentage;
1733
+ parent.activeObj.activePoint.endY -= (maxDimension.height / 100) * percentage;
1734
+ }
1735
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
1736
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1737
+ parent.notify('shape', { prop: 'updateFontSize', onPropertyChange: false,
1738
+ value: { obj: parent.activeObj } });
1739
+ }
1740
+ else {
1741
+ var splitWords = void 0;
1742
+ if (parent.activeObj.shape !== undefined) {
1743
+ splitWords = parent.activeObj.shape.split('-');
1744
+ }
1745
+ if (parent.activeObj.shape === 'crop-custom' || (parent.activeObj.shape !== undefined && splitWords[0] !== 'crop')) {
1746
+ this.adjustSWPoints(parent.activeObj.activePoint, x, y, parent.activeObj.rotatedAngle);
1747
+ if (parent.activeObj.activePoint.startX > parent.activeObj.activePoint.endX) {
1748
+ var temp = parent.activeObj.activePoint.startX;
1749
+ parent.activeObj.activePoint.startX = parent.activeObj.activePoint.endX;
1750
+ parent.activeObj.activePoint.endX = temp;
1751
+ this.dragElement = parent.upperCanvas.style.cursor = parent.cursor = 'se-resize';
1752
+ }
1753
+ if (parent.activeObj.activePoint.endY < parent.activeObj.activePoint.startY) {
1754
+ var temp = parent.activeObj.activePoint.endY;
1755
+ parent.activeObj.activePoint.endY = parent.activeObj.activePoint.startY;
1756
+ parent.activeObj.activePoint.startY = temp;
1757
+ this.dragElement = parent.upperCanvas.style.cursor = parent.cursor = 'nw-resize';
1758
+ }
1759
+ this.preventDraggingInvertly();
1760
+ }
1761
+ else {
1762
+ if (parent.activeObj.activePoint.startX < x && parent.activeObj.activePoint.endY > y) {
1763
+ width = x - parent.activeObj.activePoint.startX;
1764
+ height = parent.activeObj.activePoint.endY - y;
1765
+ scale = Math.min(width, height);
1766
+ var newScale = this.getScaleRatio(scale);
1767
+ parent.activeObj.activePoint.startX += newScale.x;
1768
+ parent.activeObj.activePoint.endY -= newScale.y;
1769
+ var endX = parent.img.destLeft > 0 ? parent.img.destLeft : 0;
1770
+ var endY = parent.img.destTop + parent.img.destHeight < parent.lowerCanvas.height ? parent.img.destTop +
1771
+ parent.img.destHeight : parent.lowerCanvas.height;
1772
+ if (parent.activeObj.activePoint.startX < endX || parent.activeObj.activePoint.endY > endY) {
1773
+ parent.activeObj.activePoint.startX -= newScale.x;
1774
+ parent.activeObj.activePoint.endY += newScale.y;
1775
+ }
1776
+ }
1777
+ else {
1778
+ width = parent.activeObj.activePoint.startX - x;
1779
+ height = y - parent.activeObj.activePoint.endY;
1780
+ scale = Math.max(width, height);
1781
+ var newScale = this.getScaleRatio(scale);
1782
+ parent.activeObj.activePoint.startX -= newScale.x;
1783
+ parent.activeObj.activePoint.endY += newScale.y;
1784
+ var endX = parent.img.destLeft > 0 ? parent.img.destLeft : 0;
1785
+ var endY = parent.img.destTop + parent.img.destHeight < parent.lowerCanvas.height ? parent.img.destTop +
1786
+ parent.img.destHeight : parent.lowerCanvas.height;
1787
+ if (parent.activeObj.activePoint.startX < endX || parent.activeObj.activePoint.endY > endY) {
1788
+ parent.activeObj.activePoint.startX += newScale.x;
1789
+ parent.activeObj.activePoint.endY -= newScale.y;
1790
+ }
1791
+ }
1792
+ }
1793
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
1794
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1795
+ this.preventInverseResize(tempActiveObj);
1796
+ }
1797
+ };
1798
+ Selection.prototype.updateSPoints = function (x, y) {
1799
+ var parent = this.parent;
1800
+ var width;
1801
+ var height;
1802
+ var scale;
1803
+ if (parent.activeObj.shape !== 'text') {
1804
+ var splitWords = void 0;
1805
+ if (parent.activeObj.shape) {
1806
+ splitWords = parent.activeObj.shape.split('-');
1807
+ }
1808
+ if (parent.activeObj.shape === 'crop-custom' || (parent.activeObj.shape && splitWords[0] !== 'crop')) {
1809
+ if (parent.activeObj.shape !== 'line' && parent.activeObj.shape !== 'arrow' && parent.activeObj.shape !== 'path' &&
1810
+ parent.activeObj.rotatedAngle !== 0 && this.dragPoint.startX) {
1811
+ if (this.dragPoint.startX && this.dragPoint.startY) {
1812
+ this.previousPoint.x = this.dragPoint.endX;
1813
+ this.previousPoint.y = this.dragPoint.endY;
1814
+ this.dragPoint.endX = x;
1815
+ this.dragPoint.endY = y;
1816
+ }
1817
+ width = (this.dragPoint.endX - this.previousPoint.x);
1818
+ height = (this.dragPoint.endY - this.previousPoint.y);
1819
+ this.adjustRotationPoints(parent.activeObj.activePoint, width, height, parent.activeObj.rotatedAngle);
1820
+ }
1821
+ else {
1822
+ parent.activeObj.activePoint.endY = y;
1823
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1824
+ }
1825
+ if (parent.activeObj.activePoint.endY < parent.activeObj.activePoint.startY) {
1826
+ var temp = parent.activeObj.activePoint.endY;
1827
+ parent.activeObj.activePoint.endY = parent.activeObj.activePoint.startY;
1828
+ parent.activeObj.activePoint.startY = temp;
1829
+ this.dragElement = this.resizedElement = 'n-resize';
1830
+ }
1831
+ this.preventDraggingInvertly();
1832
+ }
1833
+ else {
1834
+ if (parent.activeObj.activePoint.endX > x && parent.activeObj.activePoint.endY > y) {
1835
+ width = parent.activeObj.activePoint.endX - x;
1836
+ height = parent.activeObj.activePoint.endY - y;
1837
+ scale = Math.min(width, height);
1838
+ var newScale = this.getScaleRatio(scale);
1839
+ parent.activeObj.activePoint.endX -= newScale.x;
1840
+ parent.activeObj.activePoint.endY -= newScale.y;
1841
+ if (parent.activeObj.activePoint.endX > (parent.img.destLeft + parent.img.destWidth) ||
1842
+ parent.activeObj.activePoint.endY > (parent.img.destTop + parent.img.destHeight)) {
1843
+ parent.activeObj.activePoint.endX += newScale.x;
1844
+ parent.activeObj.activePoint.endY += newScale.y;
1845
+ }
1846
+ }
1847
+ else {
1848
+ width = x - parent.activeObj.activePoint.endX;
1849
+ height = y - parent.activeObj.activePoint.endY;
1850
+ scale = Math.max(width, height);
1851
+ var newScale = this.getScaleRatio(scale);
1852
+ parent.activeObj.activePoint.endX += newScale.x;
1853
+ parent.activeObj.activePoint.endY += newScale.x;
1854
+ if (parent.activeObj.activePoint.endX > (parent.img.destLeft + parent.img.destWidth) ||
1855
+ parent.activeObj.activePoint.endY > (parent.img.destTop + parent.img.destHeight)) {
1856
+ parent.activeObj.activePoint.endX -= newScale.x;
1857
+ parent.activeObj.activePoint.endY -= newScale.y;
1858
+ }
1859
+ }
1860
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
1861
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1862
+ }
1863
+ }
1864
+ };
1865
+ Selection.prototype.updateSEPoints = function (x, y, maxDimension) {
1866
+ var parent = this.parent;
1867
+ var diff;
1868
+ var width;
1869
+ var height;
1870
+ var scale;
1871
+ var percentage;
1872
+ var prevDiffX = this.diffPoint.x;
1873
+ var prevDiffY = this.diffPoint.y;
1874
+ var tempActiveObj = extend({}, parent.activeObj, null, true);
1875
+ if (parent.activeObj.shape === 'text') {
1876
+ if (this.oldPoint.x === undefined && this.oldPoint.y === undefined) {
1877
+ this.diffPoint.x = x - parent.activeObj.activePoint.endX;
1878
+ this.diffPoint.y = y - parent.activeObj.activePoint.endY;
1879
+ }
1880
+ else {
1881
+ this.diffPoint.x = x - this.oldPoint.x;
1882
+ this.diffPoint.y = y - this.oldPoint.y;
1883
+ }
1884
+ this.oldPoint.x = x;
1885
+ this.oldPoint.y = y;
1886
+ if (this.diffPoint.x >= prevDiffX && this.diffPoint.y >= prevDiffY) {
1887
+ diff = Math.max(this.diffPoint.x, this.diffPoint.y);
1888
+ }
1889
+ else {
1890
+ diff = Math.min(this.diffPoint.x, this.diffPoint.y);
1891
+ }
1892
+ percentage = (diff / 10);
1893
+ parent.activeObj.activePoint.endX += (maxDimension.width / 50) * percentage;
1894
+ parent.activeObj.activePoint.endY += (maxDimension.height / 50) * percentage;
1895
+ if (this.preventTextDraggingInvertly()) {
1896
+ parent.activeObj.activePoint.endX -= (maxDimension.width / 50) * percentage;
1897
+ parent.activeObj.activePoint.endY -= (maxDimension.height / 50) * percentage;
1898
+ }
1899
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
1900
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1901
+ parent.notify('shape', { prop: 'updateFontSize', onPropertyChange: false,
1902
+ value: { obj: parent.activeObj } });
1903
+ }
1904
+ else {
1905
+ var splitWords = void 0;
1906
+ if (parent.activeObj.shape !== undefined) {
1907
+ splitWords = parent.activeObj.shape.split('-');
1908
+ }
1909
+ if (parent.activeObj.shape === 'crop-custom' || (parent.activeObj.shape !== undefined && splitWords[0] !== 'crop')) {
1910
+ this.adjustSEPoints(parent.activeObj.activePoint, x, y, parent.activeObj.rotatedAngle);
1911
+ if (parent.activeObj.activePoint.endX < parent.activeObj.activePoint.startX) {
1912
+ var temp = parent.activeObj.activePoint.endX;
1913
+ parent.activeObj.activePoint.endX = parent.activeObj.activePoint.startX;
1914
+ parent.activeObj.activePoint.startX = temp;
1915
+ this.dragElement = parent.upperCanvas.style.cursor = parent.cursor = 'sw-resize';
1916
+ }
1917
+ if (parent.activeObj.activePoint.endY < parent.activeObj.activePoint.startY) {
1918
+ var temp = parent.activeObj.activePoint.endY;
1919
+ parent.activeObj.activePoint.endY = parent.activeObj.activePoint.startY;
1920
+ parent.activeObj.activePoint.startY = temp;
1921
+ this.dragElement = parent.upperCanvas.style.cursor = parent.cursor = 'ne-resize';
1922
+ }
1923
+ this.preventDraggingInvertly();
1924
+ }
1925
+ else {
1926
+ if (parent.activeObj.activePoint.endX > x && parent.activeObj.activePoint.endY > y) {
1927
+ width = parent.activeObj.activePoint.endX - x;
1928
+ height = parent.activeObj.activePoint.endY - y;
1929
+ scale = Math.min(width, height);
1930
+ var newScale = this.getScaleRatio(scale);
1931
+ parent.activeObj.activePoint.endX -= newScale.x;
1932
+ parent.activeObj.activePoint.endY -= newScale.y;
1933
+ var endX = parent.img.destLeft + parent.img.destWidth < parent.lowerCanvas.width ?
1934
+ parent.img.destLeft + parent.img.destWidth : parent.lowerCanvas.width;
1935
+ var endY = parent.img.destTop + parent.img.destHeight < parent.lowerCanvas.height ?
1936
+ parent.img.destTop + parent.img.destHeight : parent.lowerCanvas.height;
1937
+ if (parent.activeObj.activePoint.endX > endX || parent.activeObj.activePoint.endY > endY) {
1938
+ parent.activeObj.activePoint.endX += newScale.x;
1939
+ parent.activeObj.activePoint.endY += newScale.y;
1940
+ }
1941
+ }
1942
+ else {
1943
+ width = x - parent.activeObj.activePoint.endX;
1944
+ height = y - parent.activeObj.activePoint.endY;
1945
+ scale = Math.max(width, height);
1946
+ var newScale = this.getScaleRatio(scale);
1947
+ parent.activeObj.activePoint.endX += newScale.x;
1948
+ parent.activeObj.activePoint.endY += newScale.y;
1949
+ var endX = parent.img.destLeft + parent.img.destWidth < parent.lowerCanvas.width ? parent.img.destLeft +
1950
+ parent.img.destWidth : parent.lowerCanvas.width;
1951
+ var endY = parent.img.destTop + parent.img.destHeight < parent.lowerCanvas.height ? parent.img.destTop +
1952
+ parent.img.destHeight : parent.lowerCanvas.height;
1953
+ if (parent.activeObj.activePoint.endX > endX || parent.activeObj.activePoint.endY > endY) {
1954
+ parent.activeObj.activePoint.endX -= newScale.x;
1955
+ parent.activeObj.activePoint.endY -= newScale.y;
1956
+ }
1957
+ }
1958
+ }
1959
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
1960
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
1961
+ this.preventInverseResize(tempActiveObj);
1962
+ }
1963
+ };
1964
+ Selection.prototype.adjustNWPoints = function (rectangle, x, y, angle) {
1965
+ var cx = rectangle.startX + rectangle.width / 2;
1966
+ var cy = rectangle.startY + rectangle.height / 2;
1967
+ var rotatedC = this.rotatePoints(rectangle.endX, rectangle.endY, cx, cy, angle);
1968
+ var newCenter = [(rotatedC[0] + x) / 2, (rotatedC[1] + y) / 2];
1969
+ var newBottomRight = this.rotatePoints(rotatedC[0], rotatedC[1], newCenter[0], newCenter[1], -angle);
1970
+ var newTopLeft = this.rotatePoints(x, y, newCenter[0], newCenter[1], -angle);
1971
+ rectangle.endX = newBottomRight[0];
1972
+ rectangle.endY = newBottomRight[1];
1973
+ rectangle.startY = newTopLeft[1];
1974
+ rectangle.startX = newTopLeft[0];
1975
+ rectangle.width = rectangle.endX - rectangle.startX;
1976
+ rectangle.height = rectangle.endY - rectangle.startY;
1977
+ return rectangle;
1978
+ };
1979
+ Selection.prototype.adjustNEPoints = function (rectangle, x, y, angle) {
1980
+ var cx = rectangle.startX + rectangle.width / 2;
1981
+ var cy = rectangle.startY + rectangle.height / 2;
1982
+ var rotatedD = this.rotatePoints(rectangle.startX, rectangle.endY, cx, cy, angle);
1983
+ var newCenter = [(rotatedD[0] + x) / 2, (rotatedD[1] + y) / 2];
1984
+ var newBottomLeft = this.rotatePoints(rotatedD[0], rotatedD[1], newCenter[0], newCenter[1], -angle);
1985
+ var newTopRight = this.rotatePoints(x, y, newCenter[0], newCenter[1], -angle);
1986
+ rectangle.startX = newBottomLeft[0];
1987
+ rectangle.endY = newBottomLeft[1];
1988
+ rectangle.width = newTopRight[0] - newBottomLeft[0];
1989
+ rectangle.height = newBottomLeft[1] - newTopRight[1];
1990
+ rectangle.endX = rectangle.startX + rectangle.width;
1991
+ rectangle.startY = rectangle.endY - rectangle.height;
1992
+ return rectangle;
1993
+ };
1994
+ Selection.prototype.adjustSWPoints = function (rectangle, x, y, angle) {
1995
+ var cx = rectangle.startX + rectangle.width / 2;
1996
+ var cy = rectangle.startY + rectangle.height / 2;
1997
+ var rotatedB = this.rotatePoints(rectangle.endX, rectangle.startY, cx, cy, angle);
1998
+ var newCenter = [(rotatedB[0] + x) / 2, (rotatedB[1] + y) / 2];
1999
+ var newTopRight = this.rotatePoints(rotatedB[0], rotatedB[1], newCenter[0], newCenter[1], -angle);
2000
+ var newBottomLeft = this.rotatePoints(x, y, newCenter[0], newCenter[1], -angle);
2001
+ rectangle.endX = newTopRight[0];
2002
+ rectangle.startY = newTopRight[1];
2003
+ rectangle.startX = newBottomLeft[0];
2004
+ rectangle.endY = newBottomLeft[1];
2005
+ rectangle.width = rectangle.endX - rectangle.startX;
2006
+ rectangle.height = rectangle.endY - rectangle.startY;
2007
+ return rectangle;
2008
+ };
2009
+ Selection.prototype.adjustSEPoints = function (rectangle, x, y, angle) {
2010
+ var cx = rectangle.startX + rectangle.width / 2;
2011
+ var cy = rectangle.startY + rectangle.height / 2;
2012
+ var rotatedA = this.rotatePoints(rectangle.startX, rectangle.startY, cx, cy, angle);
2013
+ var newCenter = [(rotatedA[0] + x) / 2, (rotatedA[1] + y) / 2];
2014
+ var newTopLeft = this.rotatePoints(rotatedA[0], rotatedA[1], newCenter[0], newCenter[1], -angle);
2015
+ var newBottomRight = this.rotatePoints(x, y, newCenter[0], newCenter[1], -angle);
2016
+ rectangle.startX = newTopLeft[0];
2017
+ rectangle.startY = newTopLeft[1];
2018
+ rectangle.width = newBottomRight[0] - newTopLeft[0];
2019
+ rectangle.height = newBottomRight[1] - newTopLeft[1];
2020
+ rectangle.endX = rectangle.startX + rectangle.width;
2021
+ rectangle.endY = rectangle.startY + rectangle.height;
2022
+ return rectangle;
2023
+ };
2024
+ Selection.prototype.adjustRotationPoints = function (rectangle, x, y, angle) {
2025
+ var cx = rectangle.startX + rectangle.width / 2;
2026
+ var cy = rectangle.startY + rectangle.height / 2;
2027
+ this.getResizeDirection(rectangle, x, y, angle);
2028
+ var rotatedA = this.rotatePoints(rectangle.startX, rectangle.startY, cx, cy, angle);
2029
+ var rotatedB = this.rotatePoints(rectangle.endX, rectangle.startY, cx, cy, angle);
2030
+ var rotatedC = this.rotatePoints(rectangle.endX, rectangle.endY, cx, cy, angle);
2031
+ var rotatedD = this.rotatePoints(rectangle.startX, rectangle.endY, cx, cy, angle);
2032
+ var newCenter = [(rotatedA[0] + rotatedC[0]) / 2, (rotatedA[1] + rotatedC[1]) / 2];
2033
+ var newTopLeft = this.rotatePoints(rotatedA[0], rotatedA[1], newCenter[0], newCenter[1], -angle);
2034
+ var newBottomLeft = this.rotatePoints(rotatedD[0], rotatedD[1], newCenter[0], newCenter[1], -angle);
2035
+ var newTopRight = this.rotatePoints(rotatedB[0], rotatedB[1], newCenter[0], newCenter[1], -angle);
2036
+ rectangle.startX = newTopLeft[0];
2037
+ rectangle.startY = newTopLeft[1];
2038
+ rectangle.endX = newTopRight[0];
2039
+ rectangle.endY = newBottomLeft[1];
2040
+ rectangle.width = rectangle.endX - rectangle.startX;
2041
+ rectangle.height = rectangle.endY - rectangle.startY;
2042
+ return rectangle;
2043
+ };
2044
+ Selection.prototype.rotatePoints = function (x, y, cx, cy, angle) {
2045
+ return [
2046
+ (x - cx) * Math.cos(angle) - (y - cy) * Math.sin(angle) + cx,
2047
+ (x - cx) * Math.sin(angle) + (y - cy) * Math.cos(angle) + cy
2048
+ ];
2049
+ };
2050
+ Selection.prototype.setResizedValue = function (element, value, x, y) {
2051
+ switch (element) {
2052
+ case 'x':
2053
+ value += x;
2054
+ break;
2055
+ case 'y':
2056
+ value += y;
2057
+ break;
2058
+ case 'abs-x':
2059
+ value += (x > 0 ? -x : Math.abs(x));
2060
+ break;
2061
+ case 'abs-y':
2062
+ value += (y > 0 ? -y : Math.abs(y));
2063
+ break;
2064
+ case 'y-abs-x':
2065
+ value += (y + ((x > 0 ? -x : Math.abs(x)) / 2));
2066
+ break;
2067
+ case 'abs-x-abs-y':
2068
+ value += ((x > 0 ? -x : Math.abs(x)) + ((y > 0 ? -y : Math.abs(y)) / 2));
2069
+ break;
2070
+ case 'abs-y-x':
2071
+ value += ((y > 0 ? -y : Math.abs(y)) + (x / 2));
2072
+ break;
2073
+ case 'x-y':
2074
+ value += (x + (y / 2));
2075
+ break;
2076
+ }
2077
+ return value;
2078
+ };
2079
+ Selection.prototype.getResizeDirection = function (rectangle, x, y, angle) {
2080
+ var rotatedAngle = angle * (180 / Math.PI);
2081
+ var element = this.getResizedElement(rotatedAngle, this.resizedElement);
2082
+ if (this.resizedElement === 'e-resize') {
2083
+ rectangle.width = this.setResizedValue(element, rectangle.width, x, y);
2084
+ rectangle.endX = rectangle.width + rectangle.startX;
2085
+ }
2086
+ else if (this.resizedElement === 'n-resize') {
2087
+ rectangle.startY = this.setResizedValue(element, rectangle.startY, x, y);
2088
+ rectangle.height = rectangle.endY - rectangle.startY;
2089
+ }
2090
+ else if (this.resizedElement === 'w-resize') {
2091
+ rectangle.startX = this.setResizedValue(element, rectangle.startX, x, y);
2092
+ rectangle.width = rectangle.startX + rectangle.endX;
2093
+ }
2094
+ else if (this.resizedElement === 's-resize') {
2095
+ rectangle.height = this.setResizedValue(element, rectangle.height, x, y);
2096
+ rectangle.endY = rectangle.height + rectangle.startY;
2097
+ }
2098
+ };
2099
+ Selection.prototype.getResizedElement = function (degree, element) {
2100
+ var resizeMappings = [];
2101
+ if (element === 'n-resize') {
2102
+ resizeMappings = [
2103
+ [337.5, 360, 'y'],
2104
+ [0, 22.5, 'y'],
2105
+ [22.5, 67.5, 'y-abs-x'],
2106
+ [67.5, 112.5, 'abs-x'],
2107
+ [112.5, 157.5, 'abs-x-abs-y'],
2108
+ [157.5, 202.5, 'abs-y'],
2109
+ [202.5, 247.5, 'abs-y-x'],
2110
+ [247.5, 292.5, 'x'],
2111
+ [292.5, 337.5, 'x-y']
2112
+ ];
2113
+ }
2114
+ else if (element === 'e-resize') {
2115
+ resizeMappings = [
2116
+ [337.5, 360, 'x'],
2117
+ [0, 22.5, 'x'],
2118
+ [22.5, 67.5, 'x-y'],
2119
+ [67.5, 112.5, 'y'],
2120
+ [112.5, 157.5, 'y-abs-x'],
2121
+ [157.5, 202.5, 'abs-x'],
2122
+ [202.5, 247.5, 'abs-x-abs-y'],
2123
+ [247.5, 292.5, 'abs-y'],
2124
+ [292.5, 337.5, 'abs-y-x']
2125
+ ];
2126
+ }
2127
+ else if (element === 's-resize') {
2128
+ resizeMappings = [
2129
+ [337.5, 360, 'y'],
2130
+ [0, 22.5, 'y'],
2131
+ [22.5, 67.5, 'y-abs-x'],
2132
+ [67.5, 112.5, 'abs-x'],
2133
+ [112.5, 157.5, 'abs-x-abs-y'],
2134
+ [157.5, 202.5, 'abs-y'],
2135
+ [202.5, 247.5, 'abs-y-x'],
2136
+ [247.5, 292.5, 'x'],
2137
+ [292.5, 337.5, 'x-y']
2138
+ ];
2139
+ }
2140
+ else if (element === 'w-resize') {
2141
+ resizeMappings = [
2142
+ [337.5, 360, 'x'],
2143
+ [0, 22.5, 'x'],
2144
+ [22.5, 67.5, 'x-y'],
2145
+ [67.5, 112.5, 'y'],
2146
+ [112.5, 157.5, 'y-abs-x'],
2147
+ [157.5, 202.5, 'abs-x'],
2148
+ [202.5, 247.5, 'abs-x-abs-y'],
2149
+ [247.5, 292.5, 'abs-y'],
2150
+ [292.5, 337.5, 'abs-y-x']
2151
+ ];
2152
+ }
2153
+ var positiveDegree = degree < 0 ? 360 - Math.abs(degree) : degree;
2154
+ for (var _i = 0, resizeMappings_2 = resizeMappings; _i < resizeMappings_2.length; _i++) {
2155
+ var _a = resizeMappings_2[_i], startDegree = _a[0], endDegree = _a[1], resizeElement = _a[2];
2156
+ if ((positiveDegree > startDegree && positiveDegree <= endDegree) ||
2157
+ (positiveDegree + 360 > startDegree && positiveDegree + 360 <= endDegree)) {
2158
+ return resizeElement;
2159
+ }
2160
+ }
2161
+ return element;
2162
+ };
2163
+ Selection.prototype.updateCursorStyles = function (x, y, type) {
2164
+ var parent = this.parent;
2165
+ var isResize = false;
2166
+ if (parent.activeObj.keyHistory !== '' && parent.activeObj.shape === undefined && !parent.currObjType.isCustomCrop &&
2167
+ !parent.currObjType.isLine && parent.currObjType.isText) {
2168
+ parent.activeObj.shape = 'text';
2169
+ }
2170
+ var actObj = extend({}, parent.activeObj, {}, true);
2171
+ if (isNullOrUndefined(actObj.topLeftCircle)) {
2172
+ return;
2173
+ }
2174
+ var degree;
2175
+ if (actObj.shapeDegree === 0) {
2176
+ degree = parent.transform.degree;
2177
+ }
2178
+ else {
2179
+ degree = parent.transform.degree - actObj.shapeDegree;
2180
+ }
2181
+ if (degree < 0) {
2182
+ degree = 360 + degree;
2183
+ }
2184
+ if (this.isObjSelected) {
2185
+ if (actObj.shape === 'line' || actObj.shape === 'arrow') {
2186
+ isResize = this.updateCursorStylesForLineArrow(x, y, actObj);
2187
+ }
2188
+ else if (actObj.shape === 'path') {
2189
+ isResize = this.updateCursorStylesForPath(x, y, actObj);
2190
+ }
2191
+ else if (actObj.rotatedAngle) {
2192
+ this.setCursorForRotatedObject(actObj, x, y, parent.upperCanvas);
2193
+ if (parent.cursor === 'grabbing') {
2194
+ parent.upperCanvas.style.cursor = this.parent.cursor = 'grabbing';
2195
+ this.dragElement = parent.cursor;
2196
+ }
2197
+ else if (parent.cursor === 'move') {
2198
+ this.dragPoint.startX = this.previousPoint.x = this.dragPoint.endX = x;
2199
+ this.dragPoint.startY = this.previousPoint.y = this.dragPoint.endY = y;
2200
+ }
2201
+ else if (parent.cursor !== 'default') {
2202
+ isResize = true;
2203
+ this.dragElement = parent.cursor;
2204
+ parent.currObjType.isResize = true;
2205
+ }
2206
+ }
2207
+ else {
2208
+ var rotationCirclePoint = this.getTransRotationPoint(actObj);
2209
+ if (x >= (actObj.topLeftCircle.startX - (actObj.topLeftCircle.radius * 2)) &&
2210
+ x <= (actObj.topLeftCircle.startX + (actObj.topLeftCircle.radius * 2)) &&
2211
+ y >= (actObj.topLeftCircle.startY - (actObj.topLeftCircle.radius * 2)) &&
2212
+ y <= (actObj.topLeftCircle.startY + (actObj.topLeftCircle.radius * 2)) && this.dragElement !== 'nw-resize') {
2213
+ actObj.topLeftCircle.startX = actObj.topLeftCircle.startY = 0;
2214
+ parent.upperCanvas.style.cursor = parent.cursor = 'nw-resize';
2215
+ isResize = true;
2216
+ this.dragElement = parent.upperCanvas.style.cursor;
2217
+ }
2218
+ else if (x >= (actObj.topLeftCircle.startX - (actObj.topLeftCircle.radius * 2)) &&
2219
+ x <= (actObj.topRightCircle.startX - (actObj.topLeftCircle.radius * 2)) &&
2220
+ y >= (actObj.topCenterCircle.startY - (actObj.topLeftCircle.radius * 2)) &&
2221
+ y <= (actObj.topCenterCircle.startY + (actObj.topLeftCircle.radius * 2)) && this.dragElement !== 'n-resize') {
2222
+ actObj.topCenterCircle.startX = actObj.topCenterCircle.startY = 0;
2223
+ parent.upperCanvas.style.cursor = parent.cursor = 'n-resize';
2224
+ isResize = true;
2225
+ this.dragElement = parent.upperCanvas.style.cursor;
2226
+ }
2227
+ else if (x >= (actObj.topRightCircle.startX - (actObj.topLeftCircle.radius * 2)) &&
2228
+ x <= (actObj.topRightCircle.startX + (actObj.topLeftCircle.radius * 2)) &&
2229
+ y >= (actObj.topRightCircle.startY - (actObj.topLeftCircle.radius * 2)) &&
2230
+ y <= (actObj.topRightCircle.startY + (actObj.topLeftCircle.radius * 2)) && this.dragElement !== 'ne-resize') {
2231
+ actObj.topRightCircle.startX = actObj.topRightCircle.startY = 0;
2232
+ parent.upperCanvas.style.cursor = parent.cursor = 'ne-resize';
2233
+ isResize = true;
2234
+ this.dragElement = parent.upperCanvas.style.cursor;
2235
+ }
2236
+ else if (x >= (actObj.centerLeftCircle.startX - (actObj.topLeftCircle.radius * 2)) &&
2237
+ x <= (actObj.centerLeftCircle.startX + (actObj.topLeftCircle.radius * 2)) &&
2238
+ y >= (actObj.topLeftCircle.startY - (actObj.topLeftCircle.radius * 2)) &&
2239
+ y <= (actObj.bottomLeftCircle.startY - (actObj.topLeftCircle.radius * 2)) && this.dragElement !== 'w-resize') {
2240
+ actObj.centerLeftCircle.startX = actObj.centerLeftCircle.startY = 0;
2241
+ parent.upperCanvas.style.cursor = parent.cursor = 'w-resize';
2242
+ isResize = true;
2243
+ this.dragElement = parent.upperCanvas.style.cursor;
2244
+ }
2245
+ else if (x >= (actObj.centerRightCircle.startX - (actObj.topLeftCircle.radius * 2)) &&
2246
+ x <= (actObj.centerRightCircle.startX + (actObj.topLeftCircle.radius * 2)) &&
2247
+ y >= (actObj.topRightCircle.startY - (actObj.topLeftCircle.radius * 2)) &&
2248
+ y <= (actObj.bottomRightCircle.startY - (actObj.topLeftCircle.radius * 2)) && this.dragElement !== 'e-resize') {
2249
+ actObj.centerRightCircle.startX = actObj.centerRightCircle.startY = 0;
2250
+ parent.upperCanvas.style.cursor = parent.cursor = 'e-resize';
2251
+ isResize = true;
2252
+ this.dragElement = parent.upperCanvas.style.cursor;
2253
+ }
2254
+ else if (x >= (actObj.bottomLeftCircle.startX - (actObj.topLeftCircle.radius * 2)) &&
2255
+ x <= (actObj.bottomLeftCircle.startX + (actObj.topLeftCircle.radius * 2)) &&
2256
+ y >= (actObj.bottomLeftCircle.startY - (actObj.topLeftCircle.radius * 2)) &&
2257
+ y <= (actObj.bottomLeftCircle.startY + (actObj.topLeftCircle.radius * 2)) && this.dragElement !== 'sw-resize') {
2258
+ actObj.bottomLeftCircle.startX = actObj.bottomLeftCircle.startY = 0;
2259
+ parent.upperCanvas.style.cursor = parent.cursor = 'sw-resize';
2260
+ isResize = true;
2261
+ this.dragElement = parent.upperCanvas.style.cursor;
2262
+ }
2263
+ else if (x >= (actObj.bottomLeftCircle.startX - (actObj.topLeftCircle.radius * 2)) &&
2264
+ x <= (actObj.bottomRightCircle.startX - (actObj.topLeftCircle.radius * 2)) &&
2265
+ y >= (actObj.bottomCenterCircle.startY - (actObj.topLeftCircle.radius * 2)) &&
2266
+ y <= (actObj.bottomCenterCircle.startY + (actObj.topLeftCircle.radius * 2)) && this.dragElement !== 's-resize') {
2267
+ actObj.bottomCenterCircle.startX = actObj.bottomCenterCircle.startY = 0;
2268
+ parent.upperCanvas.style.cursor = parent.cursor = 's-resize';
2269
+ isResize = true;
2270
+ this.dragElement = parent.upperCanvas.style.cursor;
2271
+ }
2272
+ else if (x >= (actObj.bottomRightCircle.startX - (actObj.topLeftCircle.radius * 2)) &&
2273
+ x <= (actObj.bottomRightCircle.startX + (actObj.topLeftCircle.radius * 2)) &&
2274
+ y >= (actObj.bottomRightCircle.startY - (actObj.topLeftCircle.radius * 2)) &&
2275
+ y <= (actObj.bottomRightCircle.startY + (actObj.topLeftCircle.radius * 2)) && this.dragElement !== 'se-resize') {
2276
+ actObj.bottomRightCircle.startX = actObj.bottomRightCircle.startY = 0;
2277
+ parent.upperCanvas.style.cursor = parent.cursor = 'se-resize';
2278
+ isResize = true;
2279
+ this.dragElement = parent.upperCanvas.style.cursor;
2280
+ }
2281
+ else if (rotationCirclePoint &&
2282
+ x >= rotationCirclePoint.x - (actObj.topLeftCircle.radius * 2) &&
2283
+ x <= rotationCirclePoint.x + (actObj.topLeftCircle.radius * 2) &&
2284
+ y >= rotationCirclePoint.y - (actObj.topLeftCircle.radius * 2) &&
2285
+ y <= rotationCirclePoint.y + (actObj.topLeftCircle.radius * 2) && this.dragElement !== 'grabbing') {
2286
+ parent.upperCanvas.style.cursor = parent.cursor = 'grabbing';
2287
+ this.dragElement = parent.upperCanvas.style.cursor;
2288
+ }
2289
+ else {
2290
+ this.dragPoint.startX = this.previousPoint.x = this.dragPoint.endX = x;
2291
+ this.dragPoint.startY = this.previousPoint.y = this.dragPoint.endY = y;
2292
+ }
2293
+ if ((actObj.shape === 'text') && (parent.cursor === 'n-resize' ||
2294
+ parent.cursor === 's-resize' || parent.cursor === 'e-resize' ||
2295
+ parent.cursor === 'w-resize')) {
2296
+ parent.upperCanvas.style.cursor = parent.cursor = 'move';
2297
+ this.dragElement = '';
2298
+ this.dragPoint.startX = this.previousPoint.x = this.dragPoint.endX = x;
2299
+ this.dragPoint.startY = this.previousPoint.y = this.dragPoint.endY = y;
2300
+ }
2301
+ }
2302
+ }
2303
+ else {
2304
+ this.dragPoint.startX = this.previousPoint.x = this.dragPoint.endX = x;
2305
+ this.dragPoint.startY = this.previousPoint.y = this.dragPoint.endY = y;
2306
+ }
2307
+ this.previousPoint.x = this.previousPoint.y = this.diffPoint.x = this.diffPoint.y = 0;
2308
+ if (type === 'touchstart') {
2309
+ if (isResize || (x >= actObj.activePoint.startX && x <= actObj.activePoint.endX
2310
+ && y >= actObj.activePoint.startY && y <= actObj.activePoint.endY) || this.dragElement === 'grabbing') {
2311
+ parent.currObjType.isDragging = true;
2312
+ }
2313
+ else if (actObj.shape === 'line' || actObj.shape === 'arrow') {
2314
+ this.setCursorForLineArrow(actObj, x, y, parent.upperCanvas);
2315
+ if (parent.cursor === 'move') {
2316
+ parent.currObjType.isDragging = true;
2317
+ }
2318
+ }
2319
+ else if (actObj.shape === 'path') {
2320
+ this.setCursorForPath(actObj, x, y, parent.upperCanvas);
2321
+ if (parent.cursor === 'move') {
2322
+ parent.currObjType.isDragging = true;
2323
+ }
2324
+ }
2325
+ }
2326
+ else {
2327
+ parent.currObjType.isDragging = true;
2328
+ }
2329
+ if (actObj.rotatedAngle !== 0 && (this.dragElement === 'e-resize' ||
2330
+ this.dragElement === 'w-resize' || this.dragElement === 'n-resize' ||
2331
+ this.dragElement === 's-resize')) {
2332
+ this.dragPoint.startX = this.previousPoint.x = this.dragPoint.endX = x;
2333
+ this.dragPoint.startY = this.previousPoint.y = this.dragPoint.endY = y;
2334
+ }
2335
+ };
2336
+ Selection.prototype.updateCursorStylesForLineArrow = function (x, y, actObj) {
2337
+ var isResize = false;
2338
+ var parent = this.parent;
2339
+ var point;
2340
+ for (var i = 0; i < 5; i++) {
2341
+ point = actObj.pointColl[i];
2342
+ if (x >= (point.x - (actObj.topLeftCircle.radius * 2)) && x <= (point.x + (actObj.topLeftCircle.radius * 2)) &&
2343
+ y >= (point.y - (actObj.topLeftCircle.radius * 2)) && y <= (point.y + (actObj.topLeftCircle.radius * 2))) {
2344
+ actObj.centerLeftCircle.startX = actObj.centerLeftCircle.startY = 0;
2345
+ this.dragElement = 'w-resize';
2346
+ isResize = true;
2347
+ break;
2348
+ }
2349
+ }
2350
+ if (!isResize) {
2351
+ for (var i = 1; i < 6; i++) {
2352
+ point = actObj.pointColl[actObj.pointColl.length - i];
2353
+ if (x >= (point.x - (actObj.topLeftCircle.radius * 2)) && x <= (point.x + (actObj.topLeftCircle.radius * 2)) &&
2354
+ y >= (point.y - (actObj.topLeftCircle.radius * 2)) && y <= (point.y + (actObj.topLeftCircle.radius * 2))) {
2355
+ actObj.centerRightCircle.startX = actObj.centerRightCircle.startY = 0;
2356
+ this.dragElement = 'e-resize';
2357
+ isResize = true;
2358
+ break;
2359
+ }
2360
+ }
2361
+ }
2362
+ if (!isResize) {
2363
+ for (var i = 0; i < actObj.pointColl.length; i++) {
2364
+ point = actObj.pointColl[i];
2365
+ if (x >= (point.x - (actObj.topLeftCircle.radius * 2)) && x <= (point.x + (actObj.topLeftCircle.radius * 2)) &&
2366
+ y >= (point.y - (actObj.topLeftCircle.radius * 2)) && y <= (point.y + (actObj.topLeftCircle.radius * 2))) {
2367
+ parent.upperCanvas.style.cursor = parent.cursor = 'move';
2368
+ this.dragPoint.startX = this.previousPoint.x = this.dragPoint.endX = x;
2369
+ this.dragPoint.startY = this.previousPoint.y = this.dragPoint.endY = y;
2370
+ break;
2371
+ }
2372
+ else {
2373
+ parent.upperCanvas.style.cursor = parent.cursor = 'default';
2374
+ }
2375
+ }
2376
+ }
2377
+ return isResize;
2378
+ };
2379
+ Selection.prototype.updateCursorStylesForPath = function (x, y, actObj) {
2380
+ var isResize = false;
2381
+ this.pathAdjustedIndex = this.setCursorForLineArrow(actObj, x, y, this.parent.upperCanvas);
2382
+ if (this.parent.cursor === 'move') {
2383
+ isResize = true;
2384
+ this.dragElement = 'pathDrag';
2385
+ }
2386
+ if (!isResize) {
2387
+ this.parent.upperCanvas.style.cursor = this.parent.cursor = 'move';
2388
+ this.dragPoint.startX = this.previousPoint.x = this.dragPoint.endX = x;
2389
+ this.dragPoint.startY = this.previousPoint.y = this.dragPoint.endY = y;
2390
+ }
2391
+ return isResize;
2392
+ };
2393
+ Selection.prototype.setTextSelection = function (width, height) {
2394
+ var parent = this.parent;
2395
+ var degree = parent.transform.degree;
2396
+ if (parent.activeObj.shapeDegree === 0) {
2397
+ degree = parent.transform.degree;
2398
+ }
2399
+ else {
2400
+ degree = parent.transform.degree - parent.activeObj.shapeDegree;
2401
+ }
2402
+ if (degree < 0) {
2403
+ degree = 360 + degree;
2404
+ }
2405
+ for (var i = 0, len = parent.activeObj.flipObjColl.length; i < len; i++) {
2406
+ var flip = parent.activeObj.flipObjColl[i].toLowerCase();
2407
+ switch (degree) {
2408
+ case 0:
2409
+ switch (flip) {
2410
+ case 'horizontal':
2411
+ parent.activeObj.activePoint = { startX: parent.activeObj.activePoint.endX - width,
2412
+ startY: parent.activeObj.activePoint.startY,
2413
+ endX: (parent.activeObj.activePoint.endX),
2414
+ endY: parent.activeObj.activePoint.startY + (height ? height : 0) };
2415
+ break;
2416
+ case 'vertical':
2417
+ parent.activeObj.activePoint.startY = parent.activeObj.activePoint.endY - height;
2418
+ parent.activeObj.activePoint = { startX: parent.activeObj.activePoint.startX,
2419
+ startY: parent.activeObj.activePoint.startY,
2420
+ endX: (parent.activeObj.activePoint.startX + (width ? width : 0)),
2421
+ endY: parent.activeObj.activePoint.endY };
2422
+ break;
2423
+ default:
2424
+ parent.activeObj.activePoint = { startX: parent.activeObj.activePoint.startX,
2425
+ startY: parent.activeObj.activePoint.startY,
2426
+ endX: (parent.activeObj.activePoint.startX + (width ? width : 0)),
2427
+ endY: parent.activeObj.activePoint.startY + (height ? height : 0) };
2428
+ break;
2429
+ }
2430
+ break;
2431
+ case 90:
2432
+ switch (flip) {
2433
+ case 'horizontal':
2434
+ parent.activeObj.activePoint.endX = parent.activeObj.activePoint.startX + height;
2435
+ parent.activeObj.activePoint = { startX: parent.activeObj.activePoint.startX,
2436
+ startY: parent.activeObj.activePoint.startY, endX: (parent.activeObj.activePoint.endX),
2437
+ endY: parent.activeObj.activePoint.startY + (width ? width : 0) };
2438
+ break;
2439
+ case 'vertical':
2440
+ parent.activeObj.activePoint.startX = parent.activeObj.activePoint.endX - height;
2441
+ parent.activeObj.activePoint = { startX: parent.activeObj.activePoint.startX,
2442
+ startY: parent.activeObj.activePoint.endY - width,
2443
+ endX: (parent.activeObj.activePoint.endX),
2444
+ endY: parent.activeObj.activePoint.endY };
2445
+ break;
2446
+ default:
2447
+ parent.activeObj.activePoint.startX = parent.activeObj.activePoint.endX - height;
2448
+ parent.activeObj.activePoint = { startX: parent.activeObj.activePoint.startX,
2449
+ startY: parent.activeObj.activePoint.startY, endX: (parent.activeObj.activePoint.endX),
2450
+ endY: parent.activeObj.activePoint.startY + (width ? width : 0) };
2451
+ break;
2452
+ }
2453
+ break;
2454
+ case 180:
2455
+ switch (flip) {
2456
+ case 'horizontal':
2457
+ parent.activeObj.activePoint.startY = parent.activeObj.activePoint.endY - height;
2458
+ parent.activeObj.activePoint = { startX: parent.activeObj.activePoint.startX,
2459
+ startY: parent.activeObj.activePoint.startY,
2460
+ endX: (parent.activeObj.activePoint.startX + width),
2461
+ endY: parent.activeObj.activePoint.endY };
2462
+ break;
2463
+ case 'vertical':
2464
+ parent.activeObj.activePoint.endY = parent.activeObj.activePoint.startY + height;
2465
+ parent.activeObj.activePoint = { endX: parent.activeObj.activePoint.endX, endY: parent.activeObj.activePoint.endY,
2466
+ startX: (parent.activeObj.activePoint.endX - (width ? width : 0)),
2467
+ startY: parent.activeObj.activePoint.startY };
2468
+ break;
2469
+ default:
2470
+ parent.activeObj.activePoint = { endX: parent.activeObj.activePoint.endX, endY: parent.activeObj.activePoint.endY,
2471
+ startX: (parent.activeObj.activePoint.endX - (width ? width : 0)),
2472
+ startY: parent.activeObj.activePoint.endY - (height ? height : 0) };
2473
+ break;
2474
+ }
2475
+ break;
2476
+ case 270:
2477
+ switch (flip) {
2478
+ case 'horizontal':
2479
+ parent.activeObj.activePoint.startX = parent.activeObj.activePoint.endX - height;
2480
+ parent.activeObj.activePoint = { startX: parent.activeObj.activePoint.startX,
2481
+ startY: parent.activeObj.activePoint.endY - (width ? width : 0),
2482
+ endX: parent.activeObj.activePoint.endX,
2483
+ endY: parent.activeObj.activePoint.endY };
2484
+ break;
2485
+ case 'vertical':
2486
+ parent.activeObj.activePoint = { startX: parent.activeObj.activePoint.startX,
2487
+ startY: parent.activeObj.activePoint.startY,
2488
+ endX: (parent.activeObj.activePoint.startX + height),
2489
+ endY: parent.activeObj.activePoint.startY + (width ? width : 0) };
2490
+ break;
2491
+ default:
2492
+ parent.activeObj.activePoint.endX = parent.activeObj.activePoint.startX + height;
2493
+ parent.activeObj.activePoint = { startX: parent.activeObj.activePoint.startX,
2494
+ startY: parent.activeObj.activePoint.endY - (width ? width : 0),
2495
+ endX: parent.activeObj.activePoint.endX,
2496
+ endY: parent.activeObj.activePoint.endY };
2497
+ break;
2498
+ }
2499
+ break;
2500
+ }
2501
+ }
2502
+ if (parent.activeObj.flipObjColl.length === 0) {
2503
+ switch (degree) {
2504
+ case 0:
2505
+ parent.activeObj.activePoint = { startX: parent.activeObj.activePoint.startX, startY: parent.activeObj.activePoint.startY,
2506
+ endX: (parent.activeObj.activePoint.startX + (width ? width : 0)),
2507
+ endY: parent.activeObj.activePoint.startY + (height ? height : 0) };
2508
+ break;
2509
+ case 90:
2510
+ parent.activeObj.activePoint.startX = parent.activeObj.activePoint.endX - height;
2511
+ parent.activeObj.activePoint = { startX: parent.activeObj.activePoint.startX, startY: parent.activeObj.activePoint.startY,
2512
+ endX: (parent.activeObj.activePoint.endX),
2513
+ endY: parent.activeObj.activePoint.startY + (width ? width : 0) };
2514
+ break;
2515
+ case 180:
2516
+ parent.activeObj.activePoint = { endX: parent.activeObj.activePoint.endX, endY: parent.activeObj.activePoint.endY,
2517
+ startX: (parent.activeObj.activePoint.endX - (width ? width : 0)),
2518
+ startY: parent.activeObj.activePoint.endY - (height ? height : 0) };
2519
+ break;
2520
+ case 270:
2521
+ parent.activeObj.activePoint.endX = parent.activeObj.activePoint.startX + height;
2522
+ parent.activeObj.activePoint = { startX: parent.activeObj.activePoint.startX,
2523
+ startY: parent.activeObj.activePoint.endY - (width ? width : 0),
2524
+ endX: parent.activeObj.activePoint.endX,
2525
+ endY: parent.activeObj.activePoint.endY };
2526
+ break;
2527
+ }
2528
+ }
2529
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
2530
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
2531
+ if (parent.transform.degree === 360 || parent.transform.degree === -360) {
2532
+ parent.transform.degree = 0;
2533
+ }
2534
+ };
2535
+ Selection.prototype.setActivePoint = function (startX, startY) {
2536
+ var parent = this.parent;
2537
+ if (isNullOrUndefined(parent.activeObj.activePoint)) {
2538
+ return;
2539
+ }
2540
+ if (parent.currObjType.isText) {
2541
+ var textWidth = startX ? startX : 0;
2542
+ var textHeight = startY ? startY : parent.activeObj.textSettings.fontSize;
2543
+ if (parent.activeObj.textSettings.fontSize === undefined) {
2544
+ parent.activeObj.textSettings.fontSize = (Math.abs(parent.baseImg.width - parent.baseImg.height)) * 0.1;
2545
+ }
2546
+ this.setTextSelection(textWidth, textHeight);
2547
+ this.mouseDownPoint.x = parent.activeObj.activePoint.endX;
2548
+ this.mouseDownPoint.y = parent.activeObj.activePoint.endY;
2549
+ if (parent.activeObj.horTopLine !== undefined) {
2550
+ parent.activeObj.activePoint = extend({}, parent.activeObj.activePoint, {}, true);
2551
+ }
2552
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'duplicate' } });
2553
+ }
2554
+ else if (startX && startY) {
2555
+ parent.activeObj.activePoint.startX = this.mouseDownPoint.x = startX;
2556
+ parent.activeObj.activePoint.startY = this.mouseDownPoint.y = startY;
2557
+ parent.currObjType.isDragging = true;
2558
+ }
2559
+ else {
2560
+ var selectInfo = parent.activeObj;
2561
+ parent.activeObj.activePoint = { startX: selectInfo.horTopLine.startX, startY: selectInfo.horTopLine.startY,
2562
+ endX: selectInfo.horTopLine.endX, endY: selectInfo.horTopLine.endY };
2563
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
2564
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
2565
+ }
2566
+ };
2567
+ Selection.prototype.mouseDownEventHandler = function (e) {
2568
+ var _this = this;
2569
+ var parent = this.parent;
2570
+ if (e.type === 'touchstart') {
2571
+ this.isTouch = true;
2572
+ }
2573
+ else {
2574
+ this.isTouch = false;
2575
+ }
2576
+ if (e.type === 'touchstart' && e.currentTarget === parent.lowerCanvas && !parent.isImageLoaded) {
2577
+ return;
2578
+ }
2579
+ this.isCropSelection = false;
2580
+ this.isPan = true;
2581
+ var splitWords;
2582
+ if (parent.activeObj.shape !== undefined) {
2583
+ splitWords = parent.activeObj.shape.split('-');
2584
+ }
2585
+ if (splitWords !== undefined && splitWords[0] === 'crop') {
2586
+ this.isCropSelection = true;
2587
+ }
2588
+ if (this.isCropSelection) {
2589
+ this.dragCanvas = parent.togglePan = true;
2590
+ }
2591
+ var imageEditorClickEventArgs = { point: this.setXYPoints(e) };
2592
+ if (isBlazor() && parent.events && parent.events.clicked.hasDelegate === true) {
2593
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
2594
+ parent.dotNetRef.invokeMethodAsync('ClickEventAsync', 'click', imageEditorClickEventArgs).then(function (imageEditorClickEventArgs) {
2595
+ _this.clickEvent(imageEditorClickEventArgs, e);
2596
+ });
2597
+ }
2598
+ else {
2599
+ parent.trigger('click', imageEditorClickEventArgs);
2600
+ this.clickEvent(imageEditorClickEventArgs, e);
2601
+ }
2602
+ };
2603
+ Selection.prototype.getImagePoints = function (x, y) {
2604
+ var parent = this.parent;
2605
+ if (x < parent.img.destLeft) {
2606
+ x = parent.img.destLeft;
2607
+ }
2608
+ else if (x > parent.img.destLeft + parent.img.destWidth) {
2609
+ x = parent.img.destLeft + parent.img.destWidth;
2610
+ }
2611
+ if (y < parent.img.destTop) {
2612
+ y = parent.img.destTop;
2613
+ }
2614
+ else if (y > parent.img.destTop + parent.img.destHeight) {
2615
+ y = parent.img.destTop + parent.img.destHeight;
2616
+ }
2617
+ return { x: x, y: y };
2618
+ };
2619
+ Selection.prototype.clickEvent = function (imageEditorClickEventArgs, e) {
2620
+ var parent = this.parent;
2621
+ var x = imageEditorClickEventArgs.point.x;
2622
+ var y = imageEditorClickEventArgs.point.y;
2623
+ var cursor = parent.activeObj.shape && parent.activeObj.shape === 'text' ?
2624
+ parent.cursor : 'default';
2625
+ if (this.currentDrawingShape !== '') {
2626
+ var object_1 = { currObj: {} };
2627
+ parent.notify('filter', { prop: 'getCurrentObj', onPropertyChange: false, value: { object: object_1 } });
2628
+ this.initialPrevObj = object_1['currObj'];
2629
+ this.initialPrevObj.objColl = extend([], parent.objColl, [], true);
2630
+ this.initialPrevObj.pointColl = extend([], parent.pointColl, [], true);
2631
+ this.initialPrevObj.afterCropActions = extend([], parent.afterCropActions, [], true);
2632
+ var selPointCollObj = { selPointColl: null };
2633
+ parent.notify('freehand-draw', { prop: 'getSelPointColl', onPropertyChange: false,
2634
+ value: { obj: selPointCollObj } });
2635
+ this.initialPrevObj.selPointColl = extend([], selPointCollObj['selPointColl'], [], true);
2636
+ this.setActivePoint(x, y);
2637
+ if (this.currentDrawingShape === 'path') {
2638
+ var point = this.getImagePoints(x, y);
2639
+ parent.activeObj.pointColl.push({ x: point.x, y: point.y });
2640
+ if (parent.activeObj.activePoint.width !== 0 && parent.activeObj.activePoint.height !== 0) {
2641
+ parent.activeObj.activePoint.width = 0;
2642
+ parent.activeObj.activePoint.height = 0;
2643
+ parent.activeObj.activePoint.startX = parent.activeObj.pointColl[parent.activeObj.pointColl.length - 1].x;
2644
+ parent.activeObj.activePoint.startY = parent.activeObj.pointColl[parent.activeObj.pointColl.length - 1].y;
2645
+ }
2646
+ }
2647
+ parent.activeObj.activePoint.endX = parent.activeObj.activePoint.startX;
2648
+ parent.activeObj.activePoint.endY = parent.activeObj.activePoint.startY;
2649
+ parent.currObjType.isDragging = true;
2650
+ return;
2651
+ }
2652
+ if (this.isCropSelection && this.dragCanvas) {
2653
+ this.setCursor(x, y);
2654
+ if (parent.cursor !== 'move' && parent.cursor !== 'crosshair' &&
2655
+ parent.cursor !== 'default' && parent.cursor !== 'grab') {
2656
+ this.isPan = false;
2657
+ }
2658
+ }
2659
+ if (parent.activeObj.shape) {
2660
+ this.isObjSelected = true;
2661
+ }
2662
+ else {
2663
+ this.isObjSelected = false;
2664
+ }
2665
+ var object = { currObj: {} };
2666
+ parent.notify('filter', { prop: 'getCurrentObj', onPropertyChange: false, value: { object: object } });
2667
+ var prevObj = object['currObj'];
2668
+ var activeObj = extend({}, parent.activeObj, null, true);
2669
+ var isShape = this.isShapeTouch(e, this.isCropSelection);
2670
+ var isFreehandDraw = this.isFreehandDrawTouch(e, this.isCropSelection);
2671
+ var isShapeClick = isShape ? isShape : this.isShapeClick(e, this.isCropSelection);
2672
+ var allowUndoRedoPush = this.applyCurrShape(isShapeClick);
2673
+ if (this.isTouch && !isShape && activeObj.shape && !this.isCropSelection) {
2674
+ if (this.applyObj(x, y)) {
2675
+ parent.okBtn(true);
2676
+ parent.notify('draw', { prop: 'setPrevActObj', onPropertyChange: false, value: { prevActObj: null } });
2677
+ }
2678
+ var prevCropObj = extend({}, parent.cropObj, {}, true);
2679
+ parent.notify('undo-redo', { prop: 'updateUndoRedoColl', onPropertyChange: false,
2680
+ value: { operation: 'shapeTransform', previousObj: prevObj, previousObjColl: prevObj.objColl,
2681
+ previousPointColl: prevObj.pointColl, previousSelPointColl: prevObj.selPointColl,
2682
+ previousCropObj: prevCropObj, previousText: null,
2683
+ currentText: null, previousFilter: null, isCircleCrop: parent.isCircleCrop } });
2684
+ if (allowUndoRedoPush) {
2685
+ parent.notify('undo-redo', { prop: 'updateCurrUrc', value: { type: 'ok' } });
2686
+ }
2687
+ }
2688
+ if (!isShape && !parent.togglePen && !this.isCropSelection) {
2689
+ if (!isBlazor()) {
2690
+ parent.notify('toolbar', { prop: 'refresh-main-toolbar', onPropertyChange: false });
2691
+ parent.notify('toolbar', { prop: 'close-contextual-toolbar', onPropertyChange: false });
2692
+ }
2693
+ else if (parent.isImageLoaded) {
2694
+ parent.updateToolbar(parent.element, 'imageLoaded', 'okBtnClick');
2695
+ }
2696
+ }
2697
+ if (this.dragCanvas && this.isPan && (parent.cursor === 'grab' || this.isTouch)
2698
+ && !isShape && !isFreehandDraw && !parent.togglePen) {
2699
+ if (this.applyObj(x, y)) {
2700
+ parent.okBtn(true);
2701
+ if (allowUndoRedoPush) {
2702
+ parent.notify('undo-redo', { prop: 'updateCurrUrc', value: { type: 'ok' } });
2703
+ }
2704
+ parent.notify('draw', { prop: 'setPrevActObj', onPropertyChange: false, value: { prevActObj: null } });
2705
+ }
2706
+ if (this.isFhdEditing) {
2707
+ parent.notify('freehand-draw', { prop: 'applyFhd', onPropertyChange: false });
2708
+ this.isFhdCustomized = false;
2709
+ if (!isBlazor()) {
2710
+ parent.notify('toolbar', { prop: 'destroy-qa-toolbar', onPropertyChange: false });
2711
+ }
2712
+ }
2713
+ if (parent.activeObj.shape && (parent.activeObj.shape === 'rectangle' ||
2714
+ parent.activeObj.shape === 'ellipse' || parent.activeObj.shape === 'line' ||
2715
+ parent.activeObj.shape === 'arrow' || parent.activeObj.shape === 'path' || parent.activeObj.shape === 'text')) {
2716
+ parent.notify('shape', { prop: 'redrawActObj', onPropertyChange: false,
2717
+ value: { x: null, y: null, isMouseDown: null } });
2718
+ parent.notify('shape', { prop: 'refreshActiveObj', onPropertyChange: false });
2719
+ if (!isBlazor()) {
2720
+ parent.notify('toolbar', { prop: 'setCurrentToolbar', value: { type: 'main' } });
2721
+ parent.notify('toolbar', { prop: 'refresh-main-toolbar', onPropertyChange: false });
2722
+ }
2723
+ else {
2724
+ parent.updateToolbar(parent.element, 'imageLoaded');
2725
+ }
2726
+ }
2727
+ this.canvasMouseDownHandler(e);
2728
+ }
2729
+ else {
2730
+ var isLineArrow = false;
2731
+ if (parent.activeObj.shape && (parent.activeObj.shape === 'line' ||
2732
+ parent.activeObj.shape === 'arrow')) {
2733
+ isLineArrow = true;
2734
+ }
2735
+ var points = this.setXYPoints(e);
2736
+ var x_1 = points.x;
2737
+ var y_1 = points.y;
2738
+ if (this.applyObj(x_1, y_1)) {
2739
+ parent.okBtn(true);
2740
+ if (allowUndoRedoPush) {
2741
+ parent.notify('undo-redo', { prop: 'updateCurrUrc', value: { type: 'ok' } });
2742
+ }
2743
+ parent.notify('draw', { prop: 'setPrevActObj', onPropertyChange: false, value: { prevActObj: null } });
2744
+ }
2745
+ parent.notify('shape', { prop: 'redrawActObj', onPropertyChange: false,
2746
+ value: { x: x_1, y: y_1, isMouseDown: true } });
2747
+ var obj = { index: null };
2748
+ parent.notify('freehand-draw', { prop: 'getFreehandDrawHoveredIndex', onPropertyChange: false, value: { obj: obj } });
2749
+ var indexObj = { freehandSelectedIndex: null };
2750
+ parent.notify('freehand-draw', { prop: 'getFreehandSelectedIndex', onPropertyChange: false, value: { obj: indexObj } });
2751
+ if (this.isFhdPoint || (this.isFhdCustomized && !parent.togglePen)) {
2752
+ if (!isNullOrUndefined(indexObj['freehandSelectedIndex']) &&
2753
+ indexObj['freehandSelectedIndex'] !== obj['index']) {
2754
+ var tempHoveredIndex = obj['index'];
2755
+ parent.okBtn();
2756
+ this.isFhdCustomized = false;
2757
+ parent.notify('freehand-draw', { prop: 'setFreehandDrawHoveredIndex', onPropertyChange: false,
2758
+ value: { index: tempHoveredIndex } });
2759
+ if (obj['index'] > -1) {
2760
+ var strokeColor = parent.pointColl[obj['index']].strokeColor;
2761
+ parent.notify('freehand-draw', { prop: 'hoverFhd', onPropertyChange: false,
2762
+ value: { strokeColor: strokeColor, strokeWidth: parent.pointColl[obj['index']].strokeWidth } });
2763
+ }
2764
+ }
2765
+ indexObj['freehandSelectedIndex'] = null;
2766
+ parent.notify('freehand-draw', { prop: 'getFreehandSelectedIndex', onPropertyChange: false, value: { obj: indexObj } });
2767
+ if (!isNullOrUndefined(obj['index']) && obj['index'] > -1) {
2768
+ parent.notify('freehand-draw', { prop: 'selectFhd', value: { type: 'ok' } });
2769
+ if (!isBlazor()) {
2770
+ parent.notify('toolbar', { prop: 'renderQAT', onPropertyChange: false, value: { isPenEdit: true } });
2771
+ }
2772
+ else {
2773
+ parent.updateToolbar(parent.element, 'pen');
2774
+ parent.updateToolbar(parent.element, 'quickAccessToolbar', 'pen');
2775
+ }
2776
+ }
2777
+ else if (indexObj['freehandSelectedIndex']) {
2778
+ parent.okBtn();
2779
+ var strokeColor = parent.pointColl[indexObj['freehandSelectedIndex']].strokeColor;
2780
+ parent.notify('freehand-draw', { prop: 'hoverFhd', onPropertyChange: false,
2781
+ value: { strokeColor: strokeColor, strokeWidth: parent.pointColl[indexObj['freehandSelectedIndex']].strokeWidth } });
2782
+ }
2783
+ }
2784
+ else {
2785
+ if (this.isFhdEditing) {
2786
+ parent.notify('freehand-draw', { prop: 'cancelFhd', value: { type: 'ok' } });
2787
+ if (document.getElementById(parent.element.id + '_quickAccessToolbarArea')) {
2788
+ document.getElementById(parent.element.id + '_quickAccessToolbarArea').style.display = 'none';
2789
+ }
2790
+ }
2791
+ if (!isBlazor()) {
2792
+ parent.notify('toolbar', { prop: 'close-contextual-toolbar', onPropertyChange: false });
2793
+ }
2794
+ this.isFhdEditing = false;
2795
+ if (isLineArrow) {
2796
+ this.setCursor(x_1, y_1);
2797
+ }
2798
+ else if (cursor !== 'default') {
2799
+ parent.upperCanvas.style.cursor = parent.cursor = cursor;
2800
+ }
2801
+ // this.setCursor(x, y);
2802
+ if (parent.cursor === 'crosshair' || (Browser.isDevice && parent.togglePen)) {
2803
+ if (parent.togglePen) {
2804
+ if (isNullOrUndefined(parent.activeObj.strokeSettings)) {
2805
+ var obj_1 = { strokeSettings: {} };
2806
+ parent.notify('shape', { prop: 'getStrokeSettings', onPropertyChange: false,
2807
+ value: { obj: obj_1 } });
2808
+ parent.activeObj.strokeSettings = obj_1['strokeSettings'];
2809
+ }
2810
+ var obj_2 = { penStrokeWidth: null };
2811
+ parent.notify('freehand-draw', { prop: 'getPenStrokeWidth', onPropertyChange: false, value: { obj: obj_2 } });
2812
+ if (isNullOrUndefined(obj_2['penStrokeWidth'])) {
2813
+ parent.notify('freehand-draw', { prop: 'setPenStrokeWidth', onPropertyChange: false, value: { value: 2 } });
2814
+ }
2815
+ this.upperContext.strokeStyle = parent.activeObj.strokeSettings.strokeColor;
2816
+ this.upperContext.fillStyle = parent.activeObj.strokeSettings.strokeColor;
2817
+ parent.notify('freehand-draw', { prop: 'freehandDownHandler', onPropertyChange: false,
2818
+ value: { e: e, canvas: parent.upperCanvas } });
2819
+ }
2820
+ else {
2821
+ parent.notify('shape', { prop: 'refreshActiveObj', onPropertyChange: false });
2822
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
2823
+ }
2824
+ parent.currObjType.isActiveObj = false;
2825
+ this.dragElement = '';
2826
+ this.dragPoint.startX = this.dragPoint.startY = this.dragPoint.endX = this.dragPoint.endY = 0;
2827
+ }
2828
+ if ((parent.cursor !== 'crosshair' && e.type.toLowerCase() === 'touchstart') ||
2829
+ (parent.currObjType.isActiveObj && parent.cursor !== 'default' && !parent.togglePen)) {
2830
+ if (parent.currObjType.isUndoAction) {
2831
+ parent.notify('undo-redo', { prop: 'refreshUrc', value: { bool: null } });
2832
+ }
2833
+ this.findTarget(x_1, y_1, e.type);
2834
+ }
2835
+ else if ((parent.currObjType.shape === '' || parent.currObjType.isCustomCrop) && !parent.togglePen && parent.cursor !== 'default') {
2836
+ this.setActivePoint(x_1, y_1);
2837
+ }
2838
+ }
2839
+ }
2840
+ this.isShapeInserted = false;
2841
+ this.tempActiveObj = extend({}, parent.activeObj, {}, true);
2842
+ };
2843
+ Selection.prototype.mouseMoveEventHandler = function (e) {
2844
+ var parent = this.parent;
2845
+ var cursor = parent.cursor;
2846
+ var canvasCursor = parent.upperCanvas.style.cursor;
2847
+ e.preventDefault();
2848
+ var bbox = parent.lowerCanvas.getBoundingClientRect();
2849
+ if (e.type === 'touchmove' && e.touches.length === 2) {
2850
+ if (this.isFirstMove) {
2851
+ this.startTouches = this.targetTouches(e.touches);
2852
+ this.tempTouches = [];
2853
+ this.tempTouches.push({ x: (e.touches[0].clientX || (e.touches[0].pageX - parent.lowerCanvas.offsetLeft) - bbox.left),
2854
+ y: (e.touches[0].clientY || (e.touches[0].pageY - parent.lowerCanvas.offsetTop)) - bbox.top });
2855
+ this.tempTouches.push({ x: (e.touches[1].clientX || (e.touches[1].pageX - parent.lowerCanvas.offsetLeft)) - bbox.left,
2856
+ y: (e.touches[1].clientY || (e.touches[1].pageY - parent.lowerCanvas.offsetTop)) - bbox.top });
2857
+ }
2858
+ else {
2859
+ var firstFingerX = (e.touches[0].clientX || (e.touches[0].pageX - parent.lowerCanvas.offsetLeft)) - bbox.left;
2860
+ var firstFingerY = (e.touches[0].clientY || (e.touches[0].pageY - parent.lowerCanvas.offsetTop)) - bbox.top;
2861
+ var secondFingerX = (e.touches[1].clientX || (e.touches[1].pageX - parent.lowerCanvas.offsetLeft)) - bbox.left;
2862
+ var secondFingerY = (e.touches[1].clientY || (e.touches[1].pageY - parent.lowerCanvas.offsetTop)) - bbox.top;
2863
+ var center = { x: firstFingerX < secondFingerX ? secondFingerX - ((secondFingerX - firstFingerX) / 2) :
2864
+ firstFingerX - ((firstFingerX - secondFingerX) / 2), y: firstFingerY < secondFingerY ?
2865
+ secondFingerY - ((secondFingerY - firstFingerY) / 2) : firstFingerY - ((firstFingerY - secondFingerY) / 2) };
2866
+ if (this.currMousePoint.x !== center.x && this.currMousePoint.y !== center.y) {
2867
+ var type = '';
2868
+ if (e.type === 'touchmove' && (parent.zoomSettings.zoomTrigger & ZoomTrigger.Pinch) === ZoomTrigger.Pinch) {
2869
+ this.zoomType = 'Pinch';
2870
+ var scale = this.calculateScale(this.startTouches, this.targetTouches(e.touches));
2871
+ this.startTouches = this.targetTouches(e.touches);
2872
+ if (scale > 1) {
2873
+ type = 'zoomIn';
2874
+ }
2875
+ else if (scale < 1) {
2876
+ type = 'zoomOut';
2877
+ }
2878
+ }
2879
+ if (type !== '') {
2880
+ parent.notify('draw', { prop: 'performPointZoom', onPropertyChange: false,
2881
+ value: { x: center.x, y: center.y, type: type } });
2882
+ }
2883
+ this.tempTouches = [];
2884
+ this.tempTouches.push({ x: e.touches[0].clientX || (e.touches[0].pageX - parent.lowerCanvas.offsetLeft),
2885
+ y: e.touches[0].clientY || (e.touches[0].pageY - parent.lowerCanvas.offsetTop) });
2886
+ this.tempTouches.push({ x: e.touches[1].clientX || (e.touches[1].pageX - parent.lowerCanvas.offsetLeft),
2887
+ y: e.touches[1].clientY || (e.touches[1].pageY - parent.lowerCanvas.offsetTop) });
2888
+ this.currMousePoint.x = center.x;
2889
+ this.currMousePoint.y = center.y;
2890
+ }
2891
+ }
2892
+ this.isFirstMove = false;
2893
+ return;
2894
+ }
2895
+ var x;
2896
+ var y;
2897
+ if (e.type === 'mousemove') {
2898
+ x = e.clientX;
2899
+ y = e.clientY;
2900
+ }
2901
+ else {
2902
+ this.touchEndPoint.x = x = e.touches[0].clientX;
2903
+ this.touchEndPoint.y = y = e.touches[0].clientY;
2904
+ }
2905
+ x -= bbox.left;
2906
+ y -= bbox.top;
2907
+ this.canvasMouseMoveHandler(e);
2908
+ var isCropSelection = false;
2909
+ var splitWords;
2910
+ if (parent.activeObj.shape !== undefined) {
2911
+ splitWords = parent.activeObj.shape.split('-');
2912
+ }
2913
+ if (splitWords !== undefined && splitWords[0] === 'crop') {
2914
+ isCropSelection = true;
2915
+ }
2916
+ if (isCropSelection) {
2917
+ parent.notify('transform', { prop: 'disableZoomOutBtn', value: { isZoomOut: true } });
2918
+ }
2919
+ parent.upperCanvas.style.cursor = canvasCursor;
2920
+ parent.cursor = cursor;
2921
+ if (parent.currObjType.isActiveObj && (parent.activeObj.activePoint !== undefined || parent.objColl.length > 0) &&
2922
+ !this.dragCanvas || parent.activeObj.activePoint !== undefined) {
2923
+ if (this.dragElement === '') {
2924
+ this.setCursor(x, y);
2925
+ if ((parent.activeObj.activePoint &&
2926
+ (parent.activeObj.activePoint.width === 0 || (!isNullOrUndefined(parent.activeObj.currIndex) &&
2927
+ this.cursorTargetId !== parent.activeObj.currIndex)))
2928
+ && parent.cursor !== 'default' &&
2929
+ parent.cursor !== 'move' && parent.cursor !== 'crosshair'
2930
+ && parent.cursor !== 'grab' && parent.cursor !== 'pointer') {
2931
+ parent.upperCanvas.style.cursor = parent.cursor = 'move';
2932
+ }
2933
+ this.findTarget(x, y, e.type);
2934
+ }
2935
+ }
2936
+ if (parent.currObjType.isDragging) {
2937
+ this.upperContext.clearRect(0, 0, parent.lowerCanvas.width, parent.lowerCanvas.height);
2938
+ this.updateActivePoint(x, y, isCropSelection);
2939
+ parent.notify('shape', { prop: 'updateTrianglePoints', onPropertyChange: false, value: { obj: parent.activeObj } });
2940
+ if (this.isPreventDragging) {
2941
+ if ((parent.activeObj.activePoint.startX > parent.img.destLeft) &&
2942
+ (parent.activeObj.activePoint.endX < parent.img.destLeft + parent.img.destWidth) &&
2943
+ (parent.activeObj.activePoint.startY > parent.img.destTop)
2944
+ && (parent.activeObj.activePoint.endY < parent.img.destTop + parent.img.destHeight)) {
2945
+ this.isPreventDragging = false;
2946
+ }
2947
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'duplicate', obj: null, isCropRatio: null,
2948
+ points: null, isPreventDrag: true, saveContext: null, isPreventSelection: null } });
2949
+ }
2950
+ else {
2951
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'duplicate', obj: null, isCropRatio: null,
2952
+ points: null, isPreventDrag: null, saveContext: null, isPreventSelection: null } });
2953
+ }
2954
+ if (isCropSelection) {
2955
+ this.dragCanvas = parent.togglePan = true;
2956
+ }
2957
+ }
2958
+ };
2959
+ Selection.prototype.mouseUpEventHandler = function (e) {
2960
+ var _this = this;
2961
+ var parent = this.parent;
2962
+ if (e.type === 'touchstart') {
2963
+ this.isTouch = false;
2964
+ }
2965
+ else if (e.type === 'touchend') {
2966
+ e.stopImmediatePropagation();
2967
+ }
2968
+ e.preventDefault();
2969
+ if (parent.togglePan) {
2970
+ this.canvasMouseUpHandler(e);
2971
+ }
2972
+ var x;
2973
+ var y;
2974
+ if (e.type === 'mouseup') {
2975
+ x = e.clientX;
2976
+ y = e.clientY;
2977
+ }
2978
+ else {
2979
+ x = this.touchEndPoint.x;
2980
+ y = this.touchEndPoint.y;
2981
+ }
2982
+ var bbox = parent.lowerCanvas.getBoundingClientRect();
2983
+ x -= bbox.left;
2984
+ y -= bbox.top;
2985
+ if (e.type === 'touchend') {
2986
+ this.startTouches = this.tempTouches = [];
2987
+ this.isFirstMove = false;
2988
+ if (parent.textArea.style.display === 'none') {
2989
+ this.timer = 0;
2990
+ }
2991
+ }
2992
+ var isCropSelection = false;
2993
+ var splitWords;
2994
+ if (parent.activeObj.shape !== undefined) {
2995
+ splitWords = parent.activeObj.shape.split('-');
2996
+ }
2997
+ if (splitWords !== undefined && splitWords[0] === 'crop') {
2998
+ isCropSelection = true;
2999
+ }
3000
+ if (isBlazor() && this.parent.eventType) {
3001
+ if (this.parent.eventType === 'pan') {
3002
+ if (parent.events && parent.events.onPanEnd.hasDelegate === true) {
3003
+ parent.dotNetRef.invokeMethodAsync('PanEventAsync', 'OnPanEnd', this.parent.panEventArgs);
3004
+ }
3005
+ }
3006
+ else if (this.parent.eventType === 'resize') {
3007
+ if (!this.isCropSelection && this.parent.events && this.parent.events.onShapeResizeEnd.hasDelegate === true) {
3008
+ this.shapeResizingArgs.currentShapeSettings = this.updatePrevShapeSettings();
3009
+ this.shapeResizingArgs.action = 'resize-end';
3010
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
3011
+ this.parent.dotNetRef.invokeMethodAsync('ShapeEventAsync', 'OnShapeResizeEnd', this.shapeResizingArgs).then(function (shapeResizingArgs) {
3012
+ _this.parent.notify('shape', { prop: 'updateShapeChangeEventArgs', onPropertyChange: false,
3013
+ value: { shapeSettings: shapeResizingArgs.currentShapeSettings } });
3014
+ });
3015
+ }
3016
+ else if (this.shapeResizingArgs && this.selectionResizingArgs && this.parent.events &&
3017
+ this.parent.events.onSelectionResizeEnd.hasDelegate === true) {
3018
+ var currentSelectionSettings = { type: this.parent.activeObj.shape,
3019
+ startX: this.shapeResizingArgs.currentShapeSettings.startX,
3020
+ startY: this.shapeResizingArgs.currentShapeSettings.startY,
3021
+ width: this.shapeResizingArgs.currentShapeSettings.width,
3022
+ height: this.shapeResizingArgs.currentShapeSettings.height };
3023
+ this.selectionResizingArgs.currentSelectionSettings = currentSelectionSettings;
3024
+ this.selectionResizingArgs.action = 'resize-end';
3025
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
3026
+ this.parent.dotNetRef.invokeMethodAsync('SelectionEventAsync', 'OnSelectionResizeEnd', this.selectionResizingArgs).then(function (selectionResizingArgs) {
3027
+ _this.parent.notify('shape', { prop: 'updateSelectionChangeEventArgs', onPropertyChange: false,
3028
+ value: { selectionSettings: selectionResizingArgs.currentSelectionSettings } });
3029
+ });
3030
+ }
3031
+ }
3032
+ else {
3033
+ if (this.shapeMovingArgs && this.parent.events && this.parent.events.onShapeDragEnd.hasDelegate === true) {
3034
+ this.shapeMovingArgs.currentShapeSettings = this.updatePrevShapeSettings();
3035
+ this.shapeMovingArgs.action = 'drag-end';
3036
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
3037
+ this.parent.dotNetRef.invokeMethodAsync('ShapeEventAsync', 'OnShapeDragEnd', this.shapeMovingArgs).then(function (shapeMovingArgs) {
3038
+ _this.parent.notify('shape', { prop: 'updateShapeChangeEventArgs', onPropertyChange: false,
3039
+ value: { shapeSettings: shapeMovingArgs.currentShapeSettings } });
3040
+ });
3041
+ }
3042
+ }
3043
+ this.shapeResizingArgs = null;
3044
+ this.shapeMovingArgs = null;
3045
+ this.parent.panEventArgs = null;
3046
+ this.parent.eventType = null;
3047
+ }
3048
+ if (this.currentDrawingShape === 'path') {
3049
+ return;
3050
+ }
3051
+ if (e.currentTarget === parent.upperCanvas) {
3052
+ this.pathAdjustedIndex = null;
3053
+ if (this.currentDrawingShape !== '') {
3054
+ if (this.currentDrawingShape === 'text') {
3055
+ var prevCropObj_1 = extend({}, parent.cropObj, {}, true);
3056
+ parent.notify('undo-redo', { prop: 'updateUndoRedoColl', onPropertyChange: false,
3057
+ value: { operation: 'shapeTransform', previousObj: this.initialPrevObj, previousObjColl: this.initialPrevObj.objColl,
3058
+ previousPointColl: this.initialPrevObj.pointColl, previousSelPointColl: this.initialPrevObj.selPointColl,
3059
+ previousCropObj: prevCropObj_1, previousText: null,
3060
+ currentText: null, previousFilter: null, isCircleCrop: null } });
3061
+ }
3062
+ else {
3063
+ parent.notify('undo-redo', { prop: 'updateUrObj', onPropertyChange: false, value: { objColl: this.initialPrevObj.objColl } });
3064
+ }
3065
+ this.isShapeInserted = true;
3066
+ this.currentDrawingShape = '';
3067
+ if (parent.activeObj.activePoint.width === 0 && parent.activeObj.activePoint.height === 0) {
3068
+ parent.notify('draw', { prop: 'performCancel', value: { isContextualToolbar: null } });
3069
+ }
3070
+ }
3071
+ this.adjustActObjForLineArrow();
3072
+ this.updPtCollForShpRot();
3073
+ parent.currObjType.shape = parent.currObjType.shape.toLowerCase();
3074
+ var prevCropObj = extend({}, parent.cropObj, {}, true);
3075
+ var object = { currObj: {} };
3076
+ parent.notify('filter', { prop: 'getCurrentObj', onPropertyChange: false, value: { object: object } });
3077
+ var prevObj = object['currObj'];
3078
+ prevObj.objColl = extend([], parent.objColl, [], true);
3079
+ prevObj.pointColl = extend([], parent.pointColl, [], true);
3080
+ prevObj.afterCropActions = extend([], parent.afterCropActions, [], true);
3081
+ var selPointCollObj = { selPointColl: null };
3082
+ parent.notify('freehand-draw', { prop: 'getSelPointColl', onPropertyChange: false,
3083
+ value: { obj: selPointCollObj } });
3084
+ prevObj.selPointColl = extend([], selPointCollObj['selPointColl'], [], true);
3085
+ if (!parent.togglePen && !isCropSelection) {
3086
+ if (this.tempObjColl && parent.activeObj.activePoint.width !== 0) {
3087
+ parent.objColl.push(parent.activeObj);
3088
+ if (JSON.stringify(parent.activeObj.activePoint) !== JSON.stringify(this.tempActiveObj.activePoint)) {
3089
+ parent.notify('undo-redo', { prop: 'updateUndoRedoColl', onPropertyChange: false,
3090
+ value: { operation: 'shapeTransform', previousObj: prevObj, previousObjColl: this.tempObjColl,
3091
+ previousPointColl: prevObj.pointColl, previousSelPointColl: prevObj.selPointColl,
3092
+ previousCropObj: prevCropObj, previousText: null,
3093
+ currentText: null, previousFilter: null, isCircleCrop: null } });
3094
+ }
3095
+ this.redrawShape(parent.objColl[parent.objColl.length - 1], true);
3096
+ this.tempObjColl = undefined;
3097
+ }
3098
+ if (!this.isFhdEditing) {
3099
+ this.applyCurrActObj(x, y);
3100
+ parent.currObjType.isResize = false;
3101
+ }
3102
+ }
3103
+ if (parent.activeObj) {
3104
+ var isCropSelection_1 = false;
3105
+ var splitWords_1;
3106
+ if (parent.activeObj.shape !== undefined) {
3107
+ splitWords_1 = parent.activeObj.shape.split('-');
3108
+ }
3109
+ if (splitWords_1 === undefined && (parent.currObjType.isCustomCrop || parent.togglePen)) {
3110
+ isCropSelection_1 = true;
3111
+ }
3112
+ else if (splitWords_1 !== undefined && splitWords_1[0] === 'crop') {
3113
+ isCropSelection_1 = true;
3114
+ }
3115
+ if (!isBlazor()) {
3116
+ if ((parent.activeObj.shape === 'rectangle') || (parent.activeObj.shape === 'ellipse')
3117
+ || (parent.activeObj.shape === 'line' || parent.activeObj.shape === 'arrow' || parent.activeObj.shape === 'path')) {
3118
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: { type: 'shapes',
3119
+ isApplyBtn: null, isCropping: null, isZooming: null, cType: null } });
3120
+ }
3121
+ else if (parent.activeObj.shape === 'text') {
3122
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: { type: 'text',
3123
+ isApplyBtn: null, isCropping: null, isZooming: null, cType: null } });
3124
+ }
3125
+ else if (this.isFhdEditing) {
3126
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: { type: 'pen',
3127
+ isApplyBtn: null, isCropping: null, isZooming: null, cType: null } });
3128
+ }
3129
+ else if (!isCropSelection_1) {
3130
+ var eventargs = { type: 'main', isApplyBtn: null, isCropping: false, isZooming: null };
3131
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: eventargs });
3132
+ }
3133
+ parent.notify('toolbar', { prop: 'update-toolbar-items', onPropertyChange: false });
3134
+ }
3135
+ else {
3136
+ if ((parent.activeObj.shape === 'rectangle') || (parent.activeObj.shape === 'ellipse')
3137
+ || (parent.activeObj.shape === 'line' || parent.activeObj.shape === 'arrow' || parent.activeObj.shape === 'path')) {
3138
+ parent.updateToolbar(parent.element, parent.activeObj.shape);
3139
+ }
3140
+ else if (parent.activeObj.shape === 'text') {
3141
+ parent.updateToolbar(parent.element, 'text');
3142
+ }
3143
+ }
3144
+ }
3145
+ }
3146
+ if (parent.activeObj.shape !== undefined) {
3147
+ splitWords = parent.activeObj.shape.split('-');
3148
+ }
3149
+ if (splitWords !== undefined && splitWords[0] === 'crop') {
3150
+ isCropSelection = true;
3151
+ }
3152
+ if (parent.activeObj.shape && !isCropSelection && e.currentTarget === parent.upperCanvas &&
3153
+ parent.textArea.style.display === 'none') {
3154
+ if (parent.activeObj.shape === 'text') {
3155
+ if (!isBlazor()) {
3156
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: { type: 'text',
3157
+ isApplyBtn: null, isCropping: null, isZooming: null, cType: null } });
3158
+ }
3159
+ }
3160
+ else {
3161
+ if (!isBlazor()) {
3162
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: { type: 'shapes',
3163
+ isApplyBtn: null, isCropping: null, isZooming: null, cType: null } });
3164
+ }
3165
+ }
3166
+ if (!isBlazor()) {
3167
+ parent.notify('toolbar', { prop: 'update-toolbar-items', onPropertyChange: false });
3168
+ parent.notify('toolbar', { prop: 'renderQAT', onPropertyChange: false, value: { isPenEdit: null } });
3169
+ }
3170
+ else {
3171
+ parent.updateToolbar(parent.element, 'quickAccessToolbar', parent.activeObj.shape);
3172
+ }
3173
+ }
3174
+ if (parent.togglePen && e.currentTarget === parent.upperCanvas) {
3175
+ parent.notify('freehand-draw', { prop: 'freehandUpHandler', onPropertyChange: false,
3176
+ value: { e: e, canvas: parent.upperCanvas, context: this.upperContext } });
3177
+ }
3178
+ else {
3179
+ parent.currObjType.shape = '';
3180
+ }
3181
+ this.dragElement = '';
3182
+ parent.currObjType.isInitialLine = parent.currObjType.isDragging = false;
3183
+ this.selMouseUpEvent();
3184
+ };
3185
+ Selection.prototype.adjustActObjForLineArrow = function (obj) {
3186
+ var isAdjusted = false;
3187
+ var parent = this.parent;
3188
+ obj = obj ? obj : parent.activeObj;
3189
+ if (obj.shape && (obj.shape === 'line' || parent.activeObj.shape === 'arrow')) {
3190
+ var temp = void 0;
3191
+ if ((this.dragElement === 'e-resize' && obj.activePoint.endX < obj.activePoint.startX) ||
3192
+ (this.dragElement === 'w-resize' && obj.activePoint.startX > obj.activePoint.endX)) {
3193
+ isAdjusted = true;
3194
+ temp = obj.activePoint.startX;
3195
+ obj.activePoint.startX = obj.activePoint.endX;
3196
+ obj.activePoint.endX = temp;
3197
+ temp = obj.activePoint.startY;
3198
+ obj.activePoint.startY = obj.activePoint.endY;
3199
+ obj.activePoint.endY = temp;
3200
+ }
3201
+ obj.activePoint.width = Math.abs(obj.activePoint.endX - obj.activePoint.startX);
3202
+ obj.activePoint.height = Math.abs(obj.activePoint.endY - obj.activePoint.startY);
3203
+ if (parent.activeObj.shape !== 'path') {
3204
+ parent.notify('shape', { prop: 'setPointCollForLineArrow', onPropertyChange: false,
3205
+ value: { obj: obj } });
3206
+ // Updating ratio for point collection
3207
+ for (var i = 0; i < obj.pointColl.length; i++) {
3208
+ obj.pointColl[i].ratioX = (obj.pointColl[i].x -
3209
+ parent.img.destLeft) / parent.img.destWidth;
3210
+ obj.pointColl[i].ratioY = (obj.pointColl[i].y -
3211
+ parent.img.destTop) / parent.img.destHeight;
3212
+ }
3213
+ }
3214
+ }
3215
+ return isAdjusted;
3216
+ };
3217
+ Selection.prototype.updPtCollForShpRot = function (obj) {
3218
+ var parent = this.parent;
3219
+ obj = obj ? obj : parent.activeObj;
3220
+ if (obj.shape && obj.rotatedAngle !== 0) {
3221
+ parent.notify('shape', { prop: 'setPointCollForShapeRotation', onPropertyChange: false,
3222
+ value: { obj: obj } });
3223
+ // Updating ratio for point collection
3224
+ for (var i = 0; i < obj.horTopLinePointColl.length; i++) {
3225
+ obj.horTopLinePointColl[i].ratioX = (obj.horTopLinePointColl[i].x -
3226
+ parent.img.destLeft) / parent.img.destWidth;
3227
+ obj.horTopLinePointColl[i].ratioY = (obj.horTopLinePointColl[i].y -
3228
+ parent.img.destTop) / parent.img.destHeight;
3229
+ }
3230
+ for (var i = 0; i < obj.horBottomLinePointColl.length; i++) {
3231
+ obj.horBottomLinePointColl[i].ratioX = (obj.horBottomLinePointColl[i].x -
3232
+ parent.img.destLeft) / parent.img.destWidth;
3233
+ obj.horBottomLinePointColl[i].ratioY = (obj.horBottomLinePointColl[i].y -
3234
+ parent.img.destTop) / parent.img.destHeight;
3235
+ }
3236
+ for (var i = 0; i < obj.verLeftLinePointColl.length; i++) {
3237
+ obj.verLeftLinePointColl[i].ratioX = (obj.verLeftLinePointColl[i].x -
3238
+ parent.img.destLeft) / parent.img.destWidth;
3239
+ obj.verLeftLinePointColl[i].ratioY = (obj.verLeftLinePointColl[i].y -
3240
+ parent.img.destTop) / parent.img.destHeight;
3241
+ }
3242
+ for (var i = 0; i < obj.verRightLinePointColl.length; i++) {
3243
+ obj.verRightLinePointColl[i].ratioX = (obj.verRightLinePointColl[i].x -
3244
+ parent.img.destLeft) / parent.img.destWidth;
3245
+ obj.verRightLinePointColl[i].ratioY = (obj.verRightLinePointColl[i].y -
3246
+ parent.img.destTop) / parent.img.destHeight;
3247
+ }
3248
+ }
3249
+ };
3250
+ Selection.prototype.setXYPoints = function (e) {
3251
+ e.preventDefault();
3252
+ var x;
3253
+ var y;
3254
+ if (e.type === 'mousedown') {
3255
+ x = e.clientX;
3256
+ y = e.clientY;
3257
+ }
3258
+ else {
3259
+ this.touchEndPoint.x = x = e.touches[0].clientX;
3260
+ this.touchEndPoint.y = y = e.touches[0].clientY;
3261
+ }
3262
+ var bbox = this.parent.lowerCanvas.getBoundingClientRect();
3263
+ x -= bbox.left;
3264
+ y -= bbox.top;
3265
+ return { x: x, y: y };
3266
+ };
3267
+ Selection.prototype.getCurrentIndex = function () {
3268
+ var index;
3269
+ var parent = this.parent;
3270
+ for (var i = 0; i < parent.objColl.length; i++) {
3271
+ if (parent.activeObj.currIndex === parent.objColl[i].currIndex) {
3272
+ index = i;
3273
+ break;
3274
+ }
3275
+ }
3276
+ return index;
3277
+ };
3278
+ Selection.prototype.isShapeClick = function (e, isCropSelection) {
3279
+ var parent = this.parent;
3280
+ var isShape = false;
3281
+ if (parent.togglePen) {
3282
+ return isShape;
3283
+ }
3284
+ if (parent.activeObj.shape && parent.activeObj.shape === 'text' && this.isShapeInserted) {
3285
+ var isTextArea = parent.textArea.style.display === 'block' ? true : false;
3286
+ var activeObj = extend({}, parent.activeObj, null, true);
3287
+ parent.notify('shape', { prop: 'redrawActObj', onPropertyChange: false,
3288
+ value: { x: null, y: null, isMouseDown: true } });
3289
+ var points = this.setXYPoints(e);
3290
+ var x = points.x;
3291
+ var y = points.y;
3292
+ isShape = this.findTargetObj(x, y, isCropSelection);
3293
+ if (!isCropSelection) {
3294
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
3295
+ }
3296
+ if (isTextArea) {
3297
+ parent.textArea.value = parent.objColl[parent.objColl.length - 1].keyHistory;
3298
+ parent.textArea.style.display = 'block';
3299
+ parent.activeObj = activeObj;
3300
+ var index = this.getCurrentIndex();
3301
+ if (isNullOrUndefined(index)) {
3302
+ parent.objColl.pop();
3303
+ }
3304
+ else {
3305
+ parent.objColl.splice(index, 1);
3306
+ }
3307
+ }
3308
+ else if (!isShape && activeObj.shape) {
3309
+ parent.activeObj = activeObj;
3310
+ var index = this.getCurrentIndex();
3311
+ if ((!isNullOrUndefined(index) &&
3312
+ JSON.stringify(parent.activeObj.activePoint) === JSON.stringify(parent.objColl[index].activePoint))) {
3313
+ parent.objColl.splice(index, 1);
3314
+ }
3315
+ else if (isNullOrUndefined(parent.activeObj.currIndex)) {
3316
+ parent.objColl.pop();
3317
+ }
3318
+ }
3319
+ }
3320
+ return isShape;
3321
+ };
3322
+ Selection.prototype.isShapeTouch = function (e, isCropSelection) {
3323
+ var parent = this.parent;
3324
+ var isShape = false;
3325
+ if (e.type === 'touchstart' && !parent.togglePen) {
3326
+ if (parent.activeObj && parent.activeObj.shape === 'text') {
3327
+ this.timer = setTimeout(this.setTimer.bind(this), 1000, e);
3328
+ }
3329
+ var isTextArea = parent.textArea.style.display === 'block' ? true : false;
3330
+ var activeObj = extend({}, parent.activeObj, null, true);
3331
+ parent.notify('shape', { prop: 'redrawActObj', onPropertyChange: false,
3332
+ value: { x: null, y: null, isMouseDown: true } });
3333
+ var points = this.setXYPoints(e);
3334
+ var x = points.x;
3335
+ var y = points.y;
3336
+ isShape = this.findTargetObj(x, y, isCropSelection);
3337
+ if (!isCropSelection) {
3338
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
3339
+ }
3340
+ if (isTextArea) {
3341
+ parent.textArea.value = parent.objColl[parent.objColl.length - 1].keyHistory;
3342
+ parent.textArea.style.display = 'block';
3343
+ parent.activeObj = activeObj;
3344
+ var index = this.getCurrentIndex();
3345
+ if (isNullOrUndefined(index)) {
3346
+ parent.objColl.pop();
3347
+ }
3348
+ else {
3349
+ parent.objColl.splice(index, 1);
3350
+ }
3351
+ }
3352
+ else if (!isShape && activeObj.shape) {
3353
+ parent.activeObj = activeObj;
3354
+ var index = this.getCurrentIndex();
3355
+ if (!isCropSelection) {
3356
+ if ((!isNullOrUndefined(index) && JSON.stringify(parent.activeObj.activePoint) ===
3357
+ JSON.stringify(parent.objColl[index].activePoint))) {
3358
+ parent.objColl.splice(index, 1);
3359
+ }
3360
+ else if (isNullOrUndefined(parent.activeObj.currIndex)) {
3361
+ parent.objColl.pop();
3362
+ }
3363
+ }
3364
+ }
3365
+ // this.timer = null;
3366
+ }
3367
+ return isShape;
3368
+ };
3369
+ Selection.prototype.isFreehandDrawTouch = function (e, isCropSelection) {
3370
+ var parent = this.parent;
3371
+ var isFreehandDraw = false;
3372
+ if (e.type === 'touchstart' && !isCropSelection && !parent.togglePen) {
3373
+ var isTextArea = parent.textArea.style.display === 'block' ? true : false;
3374
+ var activeObj = extend({}, parent.activeObj, null, true);
3375
+ parent.notify('shape', { prop: 'redrawActObj', onPropertyChange: false,
3376
+ value: { x: null, y: null, isMouseDown: true } });
3377
+ var points = this.setXYPoints(e);
3378
+ var x = points.x;
3379
+ var y = points.y;
3380
+ this.setCursor(x, y);
3381
+ if (this.isFhdPoint) {
3382
+ isFreehandDraw = true;
3383
+ }
3384
+ if (isTextArea) {
3385
+ parent.textArea.value = parent.objColl[parent.objColl.length - 1].keyHistory;
3386
+ parent.textArea.style.display = 'block';
3387
+ parent.activeObj = activeObj;
3388
+ var index = this.getCurrentIndex();
3389
+ if (isNullOrUndefined(index)) {
3390
+ parent.objColl.pop();
3391
+ }
3392
+ else {
3393
+ parent.objColl.splice(index, 1);
3394
+ }
3395
+ }
3396
+ else if (activeObj.shape) {
3397
+ parent.activeObj = activeObj;
3398
+ var index = this.getCurrentIndex();
3399
+ if (!isCropSelection) {
3400
+ if ((!isNullOrUndefined(index) && JSON.stringify(parent.activeObj.activePoint) ===
3401
+ JSON.stringify(parent.objColl[index].activePoint))) {
3402
+ parent.objColl.splice(index, 1);
3403
+ }
3404
+ else if (isNullOrUndefined(parent.activeObj.currIndex)) {
3405
+ parent.objColl.pop();
3406
+ }
3407
+ }
3408
+ }
3409
+ }
3410
+ return isFreehandDraw;
3411
+ };
3412
+ Selection.prototype.applyObj = function (x, y) {
3413
+ var parent = this.parent;
3414
+ var isApply = false;
3415
+ if (parent.activeObj.shape && (parent.activeObj.shape === 'rectangle' || parent.activeObj.shape === 'ellipse' ||
3416
+ parent.activeObj.shape === 'text' || parent.activeObj.shape === 'line' || parent.activeObj.shape === 'arrow' ||
3417
+ parent.activeObj.shape === 'path')) {
3418
+ if (x >= (parent.activeObj.activePoint.startX - (parent.activeObj.topLeftCircle.radius * 2)) &&
3419
+ x <= (parent.activeObj.activePoint.endX + (parent.activeObj.topLeftCircle.radius * 2)) &&
3420
+ y >= (parent.activeObj.activePoint.startY - (parent.activeObj.topLeftCircle.radius * 2)) &&
3421
+ y <= (parent.activeObj.activePoint.endY + (parent.activeObj.topLeftCircle.radius * 2))) {
3422
+ isApply = false;
3423
+ }
3424
+ else if (parent.upperCanvas.style.cursor !== 'default' && parent.upperCanvas.style.cursor !== 'grab' &&
3425
+ parent.upperCanvas.style.cursor !== 'crosshair' && parent.upperCanvas.style.cursor !== 'pointer') {
3426
+ isApply = false;
3427
+ }
3428
+ else {
3429
+ isApply = true;
3430
+ }
3431
+ }
3432
+ return isApply;
3433
+ };
3434
+ Selection.prototype.applyCurrShape = function (isShapeClick) {
3435
+ var parent = this.parent;
3436
+ var isApply = false;
3437
+ if (parent.togglePen) {
3438
+ return isApply;
3439
+ }
3440
+ var obj = extend({}, parent.activeObj, null, true);
3441
+ if (this.isShapeInserted && parent.activeObj.shape === 'text' && isShapeClick) {
3442
+ this.isInitialTextEdited = true;
3443
+ parent.notify('draw', { prop: 'setShapeTextInsert', onPropertyChange: false, value: { bool: true } });
3444
+ }
3445
+ if (parent.textArea.style.display === 'block') {
3446
+ var activeObj = extend({}, parent.activeObj, null, true);
3447
+ parent.notify('shape', { prop: 'redrawActObj', onPropertyChange: false,
3448
+ value: { x: null, y: null, isMouseDown: null } });
3449
+ obj = extend({}, parent.objColl[parent.objColl.length - 1], null, true);
3450
+ parent.objColl.pop();
3451
+ parent.activeObj = extend({}, activeObj, null, true);
3452
+ parent.textArea.value = obj.keyHistory;
3453
+ parent.textArea.style.display = 'block';
3454
+ var strokeColor = obj.strokeSettings.strokeColor.split('(')[0] === 'rgb' ?
3455
+ this.rgbToHex(parseFloat(obj.strokeSettings.strokeColor.split('(')[1].split(',')[0]), parseFloat(obj.strokeSettings.strokeColor.split('(')[1].split(',')[1]), parseFloat(obj.strokeSettings.strokeColor.split('(')[1].split(',')[2])) :
3456
+ obj.strokeSettings.strokeColor;
3457
+ if (strokeColor === '#ffffff') {
3458
+ strokeColor = '#fff';
3459
+ }
3460
+ if (this.tempActiveObj.strokeSettings.strokeColor === '#ffffff') {
3461
+ this.tempActiveObj.strokeSettings.strokeColor = '#fff';
3462
+ }
3463
+ if (obj.keyHistory !== this.tempActiveObj.keyHistory ||
3464
+ strokeColor !== this.tempActiveObj.strokeSettings.strokeColor ||
3465
+ obj.textSettings.fontFamily !== this.tempActiveObj.textSettings.fontFamily ||
3466
+ Math.round(obj.textSettings.fontSize) !== Math.round(this.tempActiveObj.textSettings.fontSize) ||
3467
+ Math.round(obj.textSettings.fontRatio) !== Math.round(this.tempActiveObj.textSettings.fontRatio) ||
3468
+ obj.textSettings.bold !== this.tempActiveObj.textSettings.bold ||
3469
+ obj.textSettings.italic !== this.tempActiveObj.textSettings.italic ||
3470
+ obj.textSettings.underline !== this.tempActiveObj.textSettings.underline) {
3471
+ isApply = true;
3472
+ }
3473
+ if (this.isInitialTextEdited && !isApply) {
3474
+ isApply = true;
3475
+ this.isInitialTextEdited = false;
3476
+ }
3477
+ }
3478
+ else {
3479
+ this.tempActiveObj.activePoint.height = Math.abs(this.tempActiveObj.activePoint.height);
3480
+ isApply = JSON.stringify(obj) !== JSON.stringify(this.tempActiveObj);
3481
+ }
3482
+ return isApply;
3483
+ };
3484
+ Selection.prototype.canvasMouseDownHandler = function (e) {
3485
+ var parent = this.parent;
3486
+ e.preventDefault();
3487
+ var x;
3488
+ var y;
3489
+ if (e.type === 'mousedown') {
3490
+ x = e.offsetX || (e.pageX - parent.lowerCanvas.offsetLeft);
3491
+ y = e.offsetY || (e.pageY - parent.lowerCanvas.offsetTop);
3492
+ }
3493
+ else {
3494
+ x = e.touches[0].clientX || (e.touches[0].pageX - parent.lowerCanvas.offsetLeft);
3495
+ y = e.touches[0].clientY || (e.touches[0].pageY - parent.lowerCanvas.offsetTop);
3496
+ }
3497
+ var bbox = parent.lowerCanvas.getBoundingClientRect();
3498
+ x -= bbox.left;
3499
+ y -= bbox.top;
3500
+ this.panDown = { x: x, y: y };
3501
+ var tempPanMoveObj = { tempPanMove: null };
3502
+ parent.notify('transform', { prop: 'getTempPanMove', onPropertyChange: false,
3503
+ value: { obj: tempPanMoveObj } });
3504
+ if (isNullOrUndefined(tempPanMoveObj['tempPanMove'])) {
3505
+ parent.notify('transform', { prop: 'setTempPanMove', onPropertyChange: false,
3506
+ value: { point: { x: x, y: y } } });
3507
+ }
3508
+ };
3509
+ Selection.prototype.canvasMouseMoveHandler = function (e) {
3510
+ var parent = this.parent;
3511
+ if (this.dragCanvas) {
3512
+ parent.lowerCanvas.style.cursor = 'grab';
3513
+ }
3514
+ else {
3515
+ this.dragCanvas = parent.togglePan = false;
3516
+ parent.lowerCanvas.style.cursor = parent.upperCanvas.style.cursor = parent.cursor = 'default';
3517
+ }
3518
+ var x;
3519
+ var y;
3520
+ if (e.type === 'mousemove') {
3521
+ x = e.offsetX;
3522
+ y = e.offsetY;
3523
+ }
3524
+ else {
3525
+ x = e.touches[0].clientX || (e.touches[0].pageX - parent.lowerCanvas.offsetLeft);
3526
+ y = e.touches[0].clientY || (e.touches[0].pageY - parent.lowerCanvas.offsetTop);
3527
+ }
3528
+ var bbox = parent.lowerCanvas.getBoundingClientRect();
3529
+ x -= bbox.left;
3530
+ y -= bbox.top;
3531
+ var panMove = { x: x, y: y };
3532
+ parent.notify('transform', { prop: 'setPanMove', onPropertyChange: false,
3533
+ value: { point: { x: x, y: y } } });
3534
+ if (this.panDown && panMove && parent.togglePan && this.dragCanvas) {
3535
+ parent.notify('transform', { prop: 'drawPannedImage', onPropertyChange: false,
3536
+ value: { xDiff: null, yDiff: null } });
3537
+ }
3538
+ };
3539
+ Selection.prototype.canvasMouseUpHandler = function (e) {
3540
+ var parent = this.parent;
3541
+ e.preventDefault();
3542
+ var panMoveObj = { panMove: null };
3543
+ parent.notify('transform', { prop: 'getPanMove', onPropertyChange: false,
3544
+ value: { obj: panMoveObj } });
3545
+ if (parent.togglePan) {
3546
+ if (this.panDown && panMoveObj['panMove'] && parent.togglePan && this.dragCanvas) {
3547
+ this.panDown = null;
3548
+ parent.notify('transform', { prop: 'setPanMove', onPropertyChange: false,
3549
+ value: { point: null } });
3550
+ parent.notify('transform', { prop: 'setTempPanMove', onPropertyChange: false,
3551
+ value: { point: null } });
3552
+ }
3553
+ }
3554
+ if (this.currentDrawingShape !== 'path') {
3555
+ parent.currObjType.isDragging = false;
3556
+ }
3557
+ };
3558
+ Selection.prototype.touchStartHandler = function (e) {
3559
+ e.preventDefault();
3560
+ if (this.touchTime === 0) {
3561
+ this.touchTime = new Date().getTime();
3562
+ }
3563
+ else {
3564
+ if (((new Date().getTime()) - this.touchTime) < 400) {
3565
+ this.parent.notify('shape', { prop: 'stopPathDrawing', onPropertyChange: false, value: { e: e } });
3566
+ this.touchTime = 0;
3567
+ }
3568
+ else {
3569
+ this.touchTime = new Date().getTime();
3570
+ }
3571
+ }
3572
+ if (e.touches.length === 2) {
3573
+ this.isFirstMove = true;
3574
+ }
3575
+ else {
3576
+ this.mouseDownEventHandler(e);
3577
+ }
3578
+ EventHandler.add(this.parent.lowerCanvas, 'touchend', this.mouseUpEventHandler, this);
3579
+ EventHandler.add(this.parent.lowerCanvas, 'touchmove', this.mouseMoveEventHandler, this);
3580
+ EventHandler.add(this.parent.upperCanvas, 'touchend', this.mouseUpEventHandler, this);
3581
+ EventHandler.add(this.parent.upperCanvas, 'touchmove', this.mouseMoveEventHandler, this);
3582
+ };
3583
+ Selection.prototype.keyDownEventHandler = function (e) {
3584
+ var _this = this;
3585
+ var parent = this.parent;
3586
+ if (e.ctrlKey && (e.key === '+' || e.key === '-')) {
3587
+ e.preventDefault();
3588
+ }
3589
+ var obj = { fileName: '', fileType: null };
3590
+ parent.notify('draw', { prop: 'getFileName', onPropertyChange: false, value: { obj: obj } });
3591
+ var beforeSave = { fileName: obj['fileName'], fileType: obj['fileType'], cancel: false };
3592
+ var splitWords;
3593
+ switch (e.key) {
3594
+ case (e.ctrlKey && 's'):
3595
+ if (isBlazor() && parent.events && parent.events.saving.hasDelegate === true) {
3596
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
3597
+ parent.dotNetRef.invokeMethodAsync('BeforeSaveEventAsync', 'BeforeSave', beforeSave).then(function (args) {
3598
+ _this.beforeSaveEvent(args, e);
3599
+ });
3600
+ }
3601
+ else {
3602
+ parent.trigger('beforeSave', beforeSave);
3603
+ this.beforeSaveEvent(beforeSave, e);
3604
+ }
3605
+ break;
3606
+ case (e.ctrlKey && 'z'):
3607
+ if (parent.allowUndoRedo) {
3608
+ parent.notify('undo-redo', { prop: 'call-undo' });
3609
+ }
3610
+ break;
3611
+ case (e.ctrlKey && 'y'):
3612
+ if (parent.allowUndoRedo) {
3613
+ parent.notify('undo-redo', { prop: 'call-redo' });
3614
+ }
3615
+ break;
3616
+ case (e.ctrlKey && '+'):
3617
+ if ((parent.zoomSettings.zoomTrigger & ZoomTrigger.Commands) === ZoomTrigger.Commands) {
3618
+ this.zoomType = 'Commands';
3619
+ parent.notify('transform', { prop: 'zoomAction', onPropertyChange: false,
3620
+ value: { zoomFactor: .1, zoomPoint: null } });
3621
+ }
3622
+ break;
3623
+ case (e.ctrlKey && '-'):
3624
+ if ((parent.zoomSettings.zoomTrigger & ZoomTrigger.Commands) === ZoomTrigger.Commands) {
3625
+ this.zoomType = 'Commands';
3626
+ parent.notify('transform', { prop: 'zoomAction', onPropertyChange: false,
3627
+ value: { zoomFactor: -.1, zoomPoint: null } });
3628
+ }
3629
+ break;
3630
+ case 'Delete':
3631
+ this.deleteItem();
3632
+ break;
3633
+ case 'Escape':
3634
+ parent.notify('draw', { prop: 'performCancel', value: { isContextualToolbar: null } });
3635
+ break;
3636
+ case 'Enter':
3637
+ if (parent.activeObj.shape) {
3638
+ splitWords = parent.activeObj.shape.split('-');
3639
+ }
3640
+ if (this.isKeyBoardCrop(e) &&
3641
+ parent.activeObj.horTopLine && (parent.activeObj.shape && splitWords[0] === 'crop')) {
3642
+ parent.crop();
3643
+ }
3644
+ break;
3645
+ case 'Tab':
3646
+ this.performTabAction();
3647
+ break;
3648
+ default:
3649
+ if (Browser.isDevice && parent.textArea.style.display === 'block') {
3650
+ setTimeout(this.textKeyDown.bind(this), 1, e);
3651
+ }
3652
+ break;
3653
+ }
3654
+ };
3655
+ Selection.prototype.isKeyBoardCrop = function (e) {
3656
+ var bool = false;
3657
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
3658
+ var target = e.target;
3659
+ if ((target.id === this.parent.element.id + '_ok' || target.id === '') && !isBlazor()) {
3660
+ bool = true;
3661
+ }
3662
+ return bool;
3663
+ };
3664
+ Selection.prototype.beforeSaveEvent = function (observableSaveArgs, e) {
3665
+ var parent = this.parent;
3666
+ if (!observableSaveArgs.cancel) {
3667
+ parent.notify('export', { prop: 'export', onPropertyChange: false,
3668
+ value: { type: observableSaveArgs.fileType, fileName: observableSaveArgs.fileName } });
3669
+ }
3670
+ e.preventDefault();
3671
+ e.stopImmediatePropagation();
3672
+ };
3673
+ Selection.prototype.handleScroll = function (e) {
3674
+ var parent = this.parent;
3675
+ var x;
3676
+ var y;
3677
+ var isInsideCanvas = false;
3678
+ if (e.type === 'mousewheel') {
3679
+ // eslint-disable-next-line
3680
+ x = e.clientX;
3681
+ y = e.clientY;
3682
+ }
3683
+ var bbox = parent.lowerCanvas.getBoundingClientRect();
3684
+ x -= bbox.left;
3685
+ y -= bbox.top;
3686
+ if (x > parent.img.destLeft && x < parent.img.destLeft + parent.img.destWidth && y > parent.img.destTop &&
3687
+ y < parent.img.destTop + parent.img.destHeight) {
3688
+ isInsideCanvas = true;
3689
+ }
3690
+ e.stopPropagation();
3691
+ if (e.ctrlKey === true && isInsideCanvas) {
3692
+ e.preventDefault();
3693
+ if (!parent.isCropTab && (parent.activeObj.shape && parent.activeObj.shape.split('-')[0] !== 'crop')) {
3694
+ parent.okBtn();
3695
+ if (!isBlazor()) {
3696
+ parent.notify('toolbar', { prop: 'close-contextual-toolbar', onPropertyChange: false });
3697
+ }
3698
+ }
3699
+ var type = '';
3700
+ if (e.type === 'mousewheel' && (parent.zoomSettings.zoomTrigger & ZoomTrigger.MouseWheel) === ZoomTrigger.MouseWheel) {
3701
+ this.zoomType = 'MouseWheel';
3702
+ // eslint-disable-next-line
3703
+ if (e.wheelDelta > 0) {
3704
+ type = 'zoomIn';
3705
+ }
3706
+ else {
3707
+ type = 'zoomOut';
3708
+ }
3709
+ }
3710
+ if (type !== '') {
3711
+ parent.notify('draw', { prop: 'performPointZoom', onPropertyChange: false,
3712
+ value: { x: x, y: y, type: type } });
3713
+ }
3714
+ }
3715
+ };
3716
+ Selection.prototype.textKeyDown = function (e) {
3717
+ var parent = this.parent;
3718
+ if (String.fromCharCode(e.which) === '\r') {
3719
+ this.textRow += 1;
3720
+ }
3721
+ parent.textArea.setAttribute('rows', this.textRow.toString());
3722
+ parent.textArea.style.height = 'auto';
3723
+ parent.textArea.style.height = parent.textArea.scrollHeight + 'px';
3724
+ parent.notify('shape', { prop: 'setTextBoxWidth', onPropertyChange: false, value: { e: e } });
3725
+ if (Browser.isDevice) {
3726
+ parent.textArea.style.width = parseFloat(parent.textArea.style.width) + parent.textArea.style.fontSize + 'px';
3727
+ }
3728
+ var rows = parent.textArea.value.split('\n');
3729
+ this.textRow = rows.length;
3730
+ parent.textArea.setAttribute('rows', this.textRow.toString());
3731
+ this.isInitialTextEdited = false;
3732
+ };
3733
+ Selection.prototype.clearSelection = function () {
3734
+ var parent = this.parent;
3735
+ if (!parent.disabled && parent.isImageLoaded) {
3736
+ parent.togglePen = false;
3737
+ parent.notify('shape', { prop: 'refreshActiveObj', onPropertyChange: false });
3738
+ this.dragElement = '';
3739
+ this.dragPoint.startX = this.dragPoint.startY = this.dragPoint.endX = this.dragPoint.endY = 0;
3740
+ parent.currObjType.shape = '';
3741
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
3742
+ parent.currObjType.isActiveObj = true;
3743
+ parent.currObjType.isCustomCrop = false;
3744
+ parent.upperCanvas.style.cursor = parent.cursor = 'default';
3745
+ }
3746
+ };
3747
+ Selection.prototype.setDragDirection = function (width, height) {
3748
+ var arcRadius = (7.5);
3749
+ var parent = this.parent;
3750
+ if (parent.img.destWidth > parent.img.destHeight) {
3751
+ parent.activeObj.activePoint.startX = this.dragPoint.startX = ((width / 2) - (height / 2))
3752
+ + arcRadius;
3753
+ parent.activeObj.activePoint.startY = this.dragPoint.startY = ((height / 2) - (height / 2))
3754
+ + arcRadius;
3755
+ parent.activeObj.activePoint.endX = ((width / 2) + (height / 2)) - arcRadius;
3756
+ parent.activeObj.activePoint.endY = ((height / 2) + (height / 2)) - arcRadius;
3757
+ }
3758
+ else {
3759
+ parent.activeObj.activePoint.startY = this.dragPoint.startX = ((height / 2) - (width) / 2)
3760
+ + arcRadius;
3761
+ parent.activeObj.activePoint.endY = ((height / 2) + (width) / 2) - arcRadius;
3762
+ parent.activeObj.activePoint.startX = this.dragPoint.startX = arcRadius;
3763
+ parent.activeObj.activePoint.endX = width - arcRadius;
3764
+ }
3765
+ };
3766
+ Selection.prototype.calcShapeRatio = function (x, y, imgWidth, imgHeight) {
3767
+ var parent = this.parent;
3768
+ var arcRadius = (7.5);
3769
+ var originalWidth = imgWidth;
3770
+ var originalHeight = imgHeight;
3771
+ var presetRatio = x / y;
3772
+ var standardSize = originalWidth >= originalHeight ? originalWidth : originalHeight;
3773
+ var width = standardSize * presetRatio;
3774
+ var height = standardSize;
3775
+ var scaleWidth = this.getScale(width, originalWidth);
3776
+ var snippetArray = [];
3777
+ for (var i = 0; i < 2; i++) {
3778
+ if (i === 0) {
3779
+ snippetArray.push(width * scaleWidth);
3780
+ }
3781
+ else {
3782
+ snippetArray.push(height * scaleWidth);
3783
+ }
3784
+ }
3785
+ width = snippetArray[0];
3786
+ height = snippetArray[1];
3787
+ var scaleHeight = this.getScale(height, originalHeight);
3788
+ var snippetArray1 = [];
3789
+ for (var i = 0; i < 2; i++) {
3790
+ if (i === 0) {
3791
+ snippetArray1.push(width * scaleHeight);
3792
+ }
3793
+ else {
3794
+ snippetArray1.push(height * scaleHeight);
3795
+ }
3796
+ }
3797
+ width = snippetArray1[0];
3798
+ height = snippetArray1[1];
3799
+ parent.activeObj.activePoint.width = width;
3800
+ parent.activeObj.activePoint.height = height;
3801
+ parent.activeObj.activePoint.startX = (this.dragPoint.startX = (originalWidth - width) / 2) + arcRadius;
3802
+ parent.activeObj.activePoint.startY = (this.dragPoint.startY = (originalHeight - height) / 2) + arcRadius;
3803
+ parent.activeObj.activePoint.endX = ((originalWidth - width) / 2 + width) - arcRadius;
3804
+ parent.activeObj.activePoint.endY = ((originalHeight - height) / 2 + height) - arcRadius;
3805
+ if (parent.activeObj.activePoint.startX < parent.img.destLeft && parent.img.destLeft + parent.img.destWidth >
3806
+ parent.lowerCanvas.clientWidth) {
3807
+ parent.activeObj.activePoint.startX = parent.img.destLeft;
3808
+ parent.activeObj.activePoint.endX = parent.activeObj.activePoint.startX + width - arcRadius;
3809
+ }
3810
+ if (parent.activeObj.activePoint.startY < parent.img.destTop && parent.img.destTop + parent.img.destHeight >
3811
+ parent.lowerCanvas.clientHeight) {
3812
+ parent.activeObj.activePoint.startY = parent.img.destTop;
3813
+ parent.activeObj.activePoint.endY = parent.activeObj.activePoint.startY + height - arcRadius;
3814
+ }
3815
+ parent.activeObj.activePoint.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
3816
+ parent.activeObj.activePoint.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
3817
+ };
3818
+ Selection.prototype.getScale = function (value, originalValue) {
3819
+ return value > originalValue ? originalValue / value : 1;
3820
+ };
3821
+ Selection.prototype.findTarget = function (x, y, type) {
3822
+ var parent = this.parent;
3823
+ if (type.toLowerCase() === 'mousedown' || type.toLowerCase() === 'touchstart') {
3824
+ var splitWords = void 0;
3825
+ var isCrop = false;
3826
+ if (parent.activeObj.shape) {
3827
+ splitWords = parent.activeObj.shape.split('-');
3828
+ if (splitWords[0] === 'crop') {
3829
+ isCrop = true;
3830
+ }
3831
+ }
3832
+ this.findTargetObj(x, y, isCrop);
3833
+ this.updateCursorStyles(x, y, type);
3834
+ }
3835
+ else {
3836
+ switch (this.dragElement.toLowerCase()) {
3837
+ case 'nw-resize':
3838
+ parent.activeObj.topLeftCircle.startX = x;
3839
+ parent.activeObj.topLeftCircle.startY = y;
3840
+ break;
3841
+ case 'n-resize':
3842
+ parent.activeObj.topCenterCircle.startX = x;
3843
+ parent.activeObj.topCenterCircle.startY = y;
3844
+ break;
3845
+ case 'ne-resize':
3846
+ parent.activeObj.topRightCircle.startX = x;
3847
+ parent.activeObj.topRightCircle.startY = y;
3848
+ break;
3849
+ case 'w-resize':
3850
+ parent.activeObj.centerLeftCircle.startX = x;
3851
+ parent.activeObj.centerLeftCircle.startY = y;
3852
+ break;
3853
+ case 'e-resize':
3854
+ parent.activeObj.centerRightCircle.startX = x;
3855
+ parent.activeObj.centerRightCircle.startY = y;
3856
+ break;
3857
+ case 'sw-resize':
3858
+ parent.activeObj.bottomLeftCircle.startX = x;
3859
+ parent.activeObj.bottomLeftCircle.startY = y;
3860
+ break;
3861
+ case 's-resize':
3862
+ parent.activeObj.bottomCenterCircle.startX = x;
3863
+ parent.activeObj.bottomCenterCircle.startY = y;
3864
+ break;
3865
+ case 'se-resize':
3866
+ parent.activeObj.bottomRightCircle.startX = x;
3867
+ parent.activeObj.bottomRightCircle.startY = y;
3868
+ break;
3869
+ default:
3870
+ if (this.dragPoint.startX && this.dragPoint.startY) {
3871
+ this.previousPoint.x = this.dragPoint.endX;
3872
+ this.previousPoint.y = this.dragPoint.endY;
3873
+ this.dragPoint.endX = x;
3874
+ this.dragPoint.endY = y;
3875
+ }
3876
+ break;
3877
+ }
3878
+ }
3879
+ };
3880
+ Selection.prototype.findTargetObj = function (x, y, isCrop) {
3881
+ var _this = this;
3882
+ var parent = this.parent;
3883
+ var isShape = false;
3884
+ if (parent.objColl.length !== 0 && !parent.currObjType.isCustomCrop && !isCrop) {
3885
+ var diffX = 0;
3886
+ var i = void 0;
3887
+ for (var index = 0; index < parent.objColl.length; index++) {
3888
+ var cursor = parent.upperCanvas.style.cursor;
3889
+ this.setCursor(x, y);
3890
+ var actObj = extend({}, parent.objColl[index], {}, true);
3891
+ if (actObj.shape === 'line' || actObj.shape === 'arrow') {
3892
+ for (var j = 0; j < actObj.pointColl.length; j++) {
3893
+ if (x >= actObj.pointColl[j].x - (actObj.topLeftCircle.radius * 2) &&
3894
+ x <= actObj.pointColl[j].x + (actObj.topLeftCircle.radius * 2) &&
3895
+ y >= actObj.pointColl[j].y - (actObj.topLeftCircle.radius * 2) &&
3896
+ y <= actObj.pointColl[j].y + (actObj.topLeftCircle.radius * 2)) {
3897
+ if (this.isTouch || parent.cursor === 'move' ||
3898
+ parent.cursor === 'grab' || this.isShapeInserted) {
3899
+ if (diffX === 0 || diffX > x - actObj.activePoint.startX) {
3900
+ diffX = x - parent.objColl[index].activePoint.startX;
3901
+ i = index;
3902
+ }
3903
+ }
3904
+ else if (parent.objColl[index].currIndex === this.tempActiveObj.currIndex) {
3905
+ i = index;
3906
+ }
3907
+ break;
3908
+ }
3909
+ }
3910
+ }
3911
+ else if (actObj.shape === 'path') {
3912
+ var cursor_1 = this.setCursorForPath(actObj, x, y, parent.upperCanvas);
3913
+ if (cursor_1 !== 'default' && cursor_1 !== 'grab') {
3914
+ if (this.isTouch || parent.cursor === 'move' || parent.cursor === 'grab' || this.isShapeInserted) {
3915
+ if (diffX === 0 || diffX > x - actObj.activePoint.startX) {
3916
+ diffX = x - parent.objColl[index].activePoint.startX;
3917
+ i = index;
3918
+ }
3919
+ }
3920
+ else if (parent.objColl[index].currIndex === this.tempActiveObj.currIndex) {
3921
+ i = index;
3922
+ }
3923
+ }
3924
+ }
3925
+ else if (actObj.rotatedAngle !== 0) {
3926
+ var cursor_2 = this.setCursorForRotatedObject(actObj, x, y, parent.upperCanvas);
3927
+ if (cursor_2 !== 'default' && cursor_2 !== 'grab') {
3928
+ if (this.isTouch || parent.cursor === 'move' || parent.cursor === 'grab' || this.isShapeInserted) {
3929
+ if (diffX === 0 || diffX > x - actObj.activePoint.startX) {
3930
+ diffX = x - parent.objColl[index].activePoint.startX;
3931
+ i = index;
3932
+ }
3933
+ }
3934
+ else if (parent.objColl[index].currIndex === this.tempActiveObj.currIndex) {
3935
+ i = index;
3936
+ }
3937
+ }
3938
+ }
3939
+ else {
3940
+ var rotationCirclePoint = this.getTransRotationPoint(actObj);
3941
+ if ((x >= (actObj.activePoint.startX - (actObj.topLeftCircle.radius * 2)) &&
3942
+ x <= (actObj.activePoint.endX + (actObj.topLeftCircle.radius * 2)) &&
3943
+ y >= (actObj.activePoint.startY - (actObj.topLeftCircle.radius * 2)) &&
3944
+ y <= (actObj.activePoint.endY + (actObj.topLeftCircle.radius * 2))) ||
3945
+ (rotationCirclePoint &&
3946
+ x >= (rotationCirclePoint.x - (actObj.topLeftCircle.radius * 2)) &&
3947
+ x <= (rotationCirclePoint.x + (actObj.topLeftCircle.radius * 2)) &&
3948
+ y >= (rotationCirclePoint.y - (actObj.topLeftCircle.radius * 2)) &&
3949
+ y <= (rotationCirclePoint.y + (actObj.topLeftCircle.radius * 2)))) {
3950
+ if (this.isTouch || cursor === 'move' || cursor === 'grabbing' || this.isShapeInserted
3951
+ || parent.cursor === 'move' || parent.cursor === 'grabbing') {
3952
+ if (diffX === 0 || diffX > x - actObj.activePoint.startX) {
3953
+ diffX = x - parent.objColl[index].activePoint.startX;
3954
+ i = index;
3955
+ }
3956
+ }
3957
+ else if (parent.objColl[index].currIndex === this.tempActiveObj.currIndex) {
3958
+ i = index;
3959
+ }
3960
+ }
3961
+ }
3962
+ }
3963
+ if (isNullOrUndefined(i)) {
3964
+ parent.notify('shape', { prop: 'refreshActiveObj', onPropertyChange: false });
3965
+ isShape = false;
3966
+ }
3967
+ else {
3968
+ this.tempObjColl = extend([], parent.objColl, [], true);
3969
+ parent.currObjType.isCustomCrop = false;
3970
+ parent.activeObj = extend({}, parent.objColl[i], {}, true);
3971
+ var temp = extend({}, parent.objColl[i], {}, true);
3972
+ parent.objColl.splice(i, 1);
3973
+ if (parent.transform.degree === 0) {
3974
+ var temp_1 = this.lowerContext.filter;
3975
+ this.lowerContext.clearRect(0, 0, parent.lowerCanvas.width, parent.lowerCanvas.height);
3976
+ parent.notify('filter', { prop: 'updateBrightFilter', onPropertyChange: false });
3977
+ this.lowerContext.drawImage(parent.baseImg, parent.img.srcLeft, parent.img.srcTop, parent.img.srcWidth, parent.img.srcHeight, parent.img.destLeft, parent.img.destTop, parent.img.destWidth, parent.img.destHeight);
3978
+ this.lowerContext.filter = 'none';
3979
+ parent.notify('shape', { prop: 'iterateObjColl', onPropertyChange: false });
3980
+ parent.activeObj = extend({}, temp_1, {}, true);
3981
+ parent.notify('freehand-draw', { prop: 'freehandRedraw', onPropertyChange: false,
3982
+ value: { context: this.lowerContext, points: null } });
3983
+ this.lowerContext.filter = temp_1;
3984
+ this.getCurrentFlipState();
3985
+ }
3986
+ else {
3987
+ parent.notify('draw', { prop: 'callUpdateCurrTransState', onPropertyChange: false });
3988
+ parent.notify('freehand-draw', { prop: 'freehandRedraw', onPropertyChange: false,
3989
+ value: { context: this.lowerContext, points: null } });
3990
+ }
3991
+ parent.notify('draw', { prop: 'clearOuterCanvas', onPropertyChange: false, value: { context: this.lowerContext } });
3992
+ if ((parent.currSelectionPoint && parent.currSelectionPoint.shape === 'crop-circle') || parent.isCircleCrop) {
3993
+ parent.notify('crop', { prop: 'cropCircle', onPropertyChange: false,
3994
+ value: { context: this.lowerContext, isSave: null, isFlip: null } });
3995
+ }
3996
+ this.setActivePoint();
3997
+ parent.activeObj = extend({}, temp, {}, true);
3998
+ var tempStrokeSettings = extend({}, parent.activeObj.strokeSettings, {}, true);
3999
+ parent.notify('draw', { prop: 'setTempStrokeSettings', onPropertyChange: false,
4000
+ value: { tempStrokeSettings: tempStrokeSettings } });
4001
+ var tempTextSettings = extend({}, parent.activeObj.textSettings, {}, true);
4002
+ parent.notify('draw', { prop: 'setTempTextSettings', onPropertyChange: false, value: { tempTextSettings: tempTextSettings } });
4003
+ var shapeSettings = this.updatePrevShapeSettings();
4004
+ var shapeChangingArgs_1 = { action: 'select', previousShapeSettings: shapeSettings,
4005
+ currentShapeSettings: shapeSettings };
4006
+ if (parent.activeObj.shape === 'line' || parent.activeObj.shape === 'arrow') {
4007
+ shapeChangingArgs_1.currentShapeSettings.width = parent.activeObj.activePoint.endX - parent.activeObj.activePoint.startX;
4008
+ shapeChangingArgs_1.currentShapeSettings.height = parent.activeObj.activePoint.endY - parent.activeObj.activePoint.startY;
4009
+ }
4010
+ this.isCropSelection = false;
4011
+ var splitWords = void 0;
4012
+ if (parent.activeObj.shape !== undefined) {
4013
+ splitWords = parent.activeObj.shape.split('-');
4014
+ }
4015
+ if (splitWords !== undefined && splitWords[0] === 'crop') {
4016
+ this.isCropSelection = true;
4017
+ }
4018
+ if (!this.isCropSelection && isBlazor() && isNullOrUndefined(this.parent.eventType) &&
4019
+ parent.events && parent.events.shapeChanging.hasDelegate === true) {
4020
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
4021
+ parent.dotNetRef.invokeMethodAsync('ShapeEventAsync', 'OnShape', shapeChangingArgs_1).then(function (shapeChangingArgs) {
4022
+ _this.shapeEvent(shapeChangingArgs);
4023
+ });
4024
+ }
4025
+ else if (!this.isCropSelection) {
4026
+ parent.trigger('shapeChanging', shapeChangingArgs_1);
4027
+ this.shapeEvent(shapeChangingArgs_1);
4028
+ }
4029
+ else {
4030
+ var selectionChangingArgs = { action: shapeChangingArgs_1.action,
4031
+ previousSelectionSettings: { type: parent.getSelectionType(parent.activeObj.shape),
4032
+ startX: shapeChangingArgs_1.previousShapeSettings.startX,
4033
+ startY: shapeChangingArgs_1.previousShapeSettings.startY,
4034
+ width: shapeChangingArgs_1.previousShapeSettings.width,
4035
+ height: shapeChangingArgs_1.previousShapeSettings.height },
4036
+ currentSelectionSettings: { type: parent.getSelectionType(parent.activeObj.shape),
4037
+ startX: shapeChangingArgs_1.currentShapeSettings.startX,
4038
+ startY: shapeChangingArgs_1.currentShapeSettings.startY,
4039
+ width: shapeChangingArgs_1.currentShapeSettings.width,
4040
+ height: shapeChangingArgs_1.currentShapeSettings.height } };
4041
+ if (isBlazor() && parent.events && parent.events.onSelectionResizeStart.hasDelegate === true) {
4042
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
4043
+ parent.dotNetRef.invokeMethodAsync('SelectionEventAsync', 'OnSelectionResizeStart', selectionChangingArgs).then(function (selectionChangingArgs) {
4044
+ shapeChangingArgs_1.currentShapeSettings.startX = selectionChangingArgs.currentSelectionSettings.startX;
4045
+ shapeChangingArgs_1.currentShapeSettings.startY = selectionChangingArgs.currentSelectionSettings.startY;
4046
+ shapeChangingArgs_1.currentShapeSettings.width = selectionChangingArgs.currentSelectionSettings.width;
4047
+ shapeChangingArgs_1.currentShapeSettings.height = selectionChangingArgs.currentSelectionSettings.height;
4048
+ _this.shapeEvent(shapeChangingArgs_1);
4049
+ });
4050
+ }
4051
+ else {
4052
+ parent.trigger('selectionChanging', selectionChangingArgs);
4053
+ shapeChangingArgs_1.currentShapeSettings.startX = selectionChangingArgs.currentSelectionSettings.startX;
4054
+ shapeChangingArgs_1.currentShapeSettings.startY = selectionChangingArgs.currentSelectionSettings.startY;
4055
+ shapeChangingArgs_1.currentShapeSettings.width = selectionChangingArgs.currentSelectionSettings.width;
4056
+ shapeChangingArgs_1.currentShapeSettings.height = selectionChangingArgs.currentSelectionSettings.height;
4057
+ this.shapeEvent(shapeChangingArgs_1);
4058
+ }
4059
+ }
4060
+ isShape = true;
4061
+ }
4062
+ }
4063
+ return isShape;
4064
+ };
4065
+ Selection.prototype.shapeEvent = function (shapeChangingArgs) {
4066
+ var parent = this.parent;
4067
+ parent.notify('shape', { prop: 'updateShapeChangeEventArgs', onPropertyChange: false,
4068
+ value: { shapeSettings: shapeChangingArgs.currentShapeSettings } });
4069
+ if (parent.activeObj.activePoint) {
4070
+ var obj = { prevActObj: null };
4071
+ parent.notify('draw', { prop: 'getPrevActObj', onPropertyChange: false, value: { obj: obj } });
4072
+ if (isNullOrUndefined(obj['prevActObj'])) {
4073
+ parent.notify('draw', { prop: 'setPrevActObj', onPropertyChange: false,
4074
+ value: { prevActObj: extend({}, parent.activeObj, {}, true) } });
4075
+ }
4076
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'duplicate', obj: parent.activeObj, isCropRatio: null,
4077
+ points: null, isPreventDrag: true, saveContext: null, isPreventSelection: true } });
4078
+ if (!this.isShapeInserted) {
4079
+ if (parent.activeObj.activePoint.startX < parent.img.destLeft) {
4080
+ this.isPreventDragging = true;
4081
+ }
4082
+ else if (parent.activeObj.activePoint.endX > parent.img.destLeft + parent.img.destWidth) {
4083
+ this.isPreventDragging = true;
4084
+ }
4085
+ else if (parent.activeObj.activePoint.startY < parent.img.destTop) {
4086
+ this.isPreventDragging = true;
4087
+ }
4088
+ else if (parent.activeObj.activePoint.endY > parent.img.destTop + parent.img.destHeight) {
4089
+ this.isPreventDragging = true;
4090
+ }
4091
+ }
4092
+ }
4093
+ };
4094
+ // eslint-disable-next-line
4095
+ Selection.prototype.targetTouches = function (touches) {
4096
+ var bbox = this.parent.lowerCanvas.getBoundingClientRect();
4097
+ var p1 = { x: touches[0].pageX - bbox.left, y: touches[0].pageY - bbox.top };
4098
+ var p2 = { x: touches[1].pageX - bbox.left, y: touches[1].pageY - bbox.top };
4099
+ var points = [p1, p2];
4100
+ return points;
4101
+ };
4102
+ Selection.prototype.calculateScale = function (startTouches, endTouches) {
4103
+ var startDistance = this.getDistance(startTouches[0], startTouches[1]);
4104
+ var endDistance = this.getDistance(endTouches[0], endTouches[1]);
4105
+ return endDistance / startDistance;
4106
+ };
4107
+ Selection.prototype.getDistance = function (a, b) {
4108
+ var x = 0;
4109
+ var y = 0;
4110
+ if (a && b) {
4111
+ x = a.x - b.x;
4112
+ y = a.y - b.y;
4113
+ }
4114
+ return Math.sqrt(x * x + y * y);
4115
+ };
4116
+ Selection.prototype.redrawShape = function (obj, isMouseUp) {
4117
+ var parent = this.parent;
4118
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
4119
+ if (JSON.stringify(obj) === JSON.stringify(parent.objColl[i])) {
4120
+ parent.objColl.splice(i, 1);
4121
+ break;
4122
+ }
4123
+ }
4124
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
4125
+ if (this.isPreventDragging) {
4126
+ if (parent.activeObj.activePoint.startX > parent.img.destLeft) {
4127
+ this.isPreventDragging = false;
4128
+ }
4129
+ if (isMouseUp && parent.activeObj.rotatedAngle !== 0) {
4130
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'duplicate', obj: null, isCropRatio: null,
4131
+ points: null, isPreventDrag: true, saveContext: null, isPreventSelection: null } });
4132
+ }
4133
+ else {
4134
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'duplicate', obj: null, isCropRatio: null,
4135
+ points: null, isPreventDrag: true, saveContext: null, isPreventSelection: null } });
4136
+ }
4137
+ }
4138
+ else {
4139
+ if (isMouseUp && parent.activeObj.rotatedAngle !== 0) {
4140
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'duplicate', obj: null, isCropRatio: null,
4141
+ points: null, isPreventDrag: true, saveContext: null, isPreventSelection: null } });
4142
+ }
4143
+ else {
4144
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'duplicate', obj: null, isCropRatio: null,
4145
+ points: null, isPreventDrag: true, saveContext: null, isPreventSelection: null } });
4146
+ }
4147
+ }
4148
+ };
4149
+ Selection.prototype.setTimer = function (e) {
4150
+ if (this.timer > 10) {
4151
+ clearTimeout(this.timer);
4152
+ this.timer = 0;
4153
+ this.parent.notify('shape', { prop: 'findTextTarget', onPropertyChange: false, value: { e: e } });
4154
+ if (Browser.isDevice) {
4155
+ this.upperContext.clearRect(0, 0, this.parent.upperCanvas.width, this.parent.upperCanvas.height);
4156
+ }
4157
+ }
4158
+ };
4159
+ Selection.prototype.applyCurrActObj = function (x, y) {
4160
+ var parent = this.parent;
4161
+ var isInside = false;
4162
+ var actObj = extend({}, parent.activeObj, {}, true);
4163
+ if (isNullOrUndefined(actObj.activePoint)) {
4164
+ return;
4165
+ }
4166
+ if ((x >= Math.floor(actObj.activePoint.startX) && x <= Math.ceil(actObj.activePoint.endX) &&
4167
+ y >= Math.floor(actObj.activePoint.startY) && y <= Math.ceil(actObj.activePoint.endY))) {
4168
+ isInside = true;
4169
+ }
4170
+ else if (actObj.shape === 'text' && this.dragElement !== '') {
4171
+ isInside = true;
4172
+ }
4173
+ else if (actObj.shape === 'line' || actObj.shape === 'arrow') {
4174
+ var smallPoint = { x: actObj.activePoint.startX < actObj.activePoint.endX ? actObj.activePoint.startX :
4175
+ actObj.activePoint.endX,
4176
+ y: actObj.activePoint.startY < actObj.activePoint.endY ? actObj.activePoint.startY : actObj.activePoint.endY };
4177
+ var largePoint = { x: actObj.activePoint.startX > actObj.activePoint.endX ? actObj.activePoint.startX :
4178
+ actObj.activePoint.endX,
4179
+ y: actObj.activePoint.startY > actObj.activePoint.endY ? actObj.activePoint.startY : actObj.activePoint.endY };
4180
+ if (x >= (Math.floor(smallPoint.x) - 5) && x <= (Math.ceil(largePoint.x) + 5) &&
4181
+ y >= (Math.floor(smallPoint.y) - 5) && y <= (Math.ceil(largePoint.y) + 5)) {
4182
+ isInside = true;
4183
+ }
4184
+ }
4185
+ else if (actObj.shape === 'path') {
4186
+ var cursor = this.setCursorForPath(actObj, x, y, parent.upperCanvas);
4187
+ if (cursor === 'move') {
4188
+ isInside = true;
4189
+ }
4190
+ }
4191
+ else if (this.dragElement === 'grabbing') {
4192
+ isInside = true;
4193
+ }
4194
+ else if (actObj.rotatedAngle !== 0) {
4195
+ var cursor = this.setCursorForRotatedObject(actObj, x, y, parent.upperCanvas);
4196
+ if ((cursor !== 'default' && cursor !== 'grab') || this.dragElement === 'n-resize' || this.dragElement === 'e-resize' ||
4197
+ this.dragElement === 's-resize' || this.dragElement === 'w-resize') {
4198
+ isInside = true;
4199
+ }
4200
+ }
4201
+ if (!isInside) {
4202
+ if (isNullOrUndefined(parent.activeObj.currIndex)) {
4203
+ parent.activeObj.currIndex = 'shape_' + (parent.objColl.length + 1);
4204
+ }
4205
+ parent.notify('shape', { prop: 'updImgRatioForActObj', onPropertyChange: false });
4206
+ if (parent.activeObj.horTopLine !== undefined && parent.activeObj.horTopLine.startX !== 0 && parent.activeObj.horTopLine.endX
4207
+ !== 0 && !parent.currObjType.isCustomCrop && parent.currObjType.shape !== '') {
4208
+ parent.objColl.push(extend({}, parent.activeObj, {}, true));
4209
+ }
4210
+ if (parent.activeObj.shape === 'text' || (parent.currObjType.shape === 'ellipse' || parent.currObjType.shape === 'rectangle' ||
4211
+ parent.currObjType.shape === 'line' || parent.activeObj.shape === 'arrow' || parent.activeObj.shape === 'path')) {
4212
+ var tempFilter = this.lowerContext.filter;
4213
+ this.lowerContext.filter = 'brightness(' + 1 + ') ' + 'contrast(' + 100 + '%) ' + 'hue-rotate(' + 0 + 'deg) ' +
4214
+ 'saturate(' + 100 + '%) ' + 'opacity(' + 1 + ') ' + 'blur(' + 0 + 'px) ' + 'sepia(0%) ' + 'grayscale(0%) ' +
4215
+ 'invert(0%)';
4216
+ for (var i = 0; i < parent.objColl.length; i++) {
4217
+ var obj = { isInside: false };
4218
+ parent.notify('crop', { prop: 'isObjInImage', onPropertyChange: false,
4219
+ value: { obj: parent.objColl[i], object: obj } });
4220
+ if (obj['isInside']) {
4221
+ parent.notify('shape', { prop: 'apply', onPropertyChange: false,
4222
+ value: { shape: parent.objColl[i].shape, obj: parent.objColl[i], canvas: null } });
4223
+ parent.notify('shape', { prop: 'refreshActiveObj', onPropertyChange: false });
4224
+ }
4225
+ }
4226
+ parent.notify('freehand-draw', { prop: 'zoomFHDColl', onPropertyChange: false, value: { isPreventApply: null } });
4227
+ this.lowerContext.filter = tempFilter;
4228
+ if (parent.activeObj.shape) {
4229
+ parent.notify('shape', { prop: 'apply', onPropertyChange: false,
4230
+ value: { shape: null, obj: null, canvas: null } });
4231
+ }
4232
+ parent.notify('draw', { prop: 'clearOuterCanvas', onPropertyChange: false, value: { context: this.lowerContext } });
4233
+ parent.notify('draw', { prop: 'clearOuterCanvas', onPropertyChange: false, value: { context: this.upperContext } });
4234
+ if (parent.isCircleCrop) {
4235
+ parent.notify('crop', { prop: 'cropCircle', onPropertyChange: false,
4236
+ value: { context: this.lowerContext, isSave: null, isFlip: null } });
4237
+ }
4238
+ }
4239
+ if (!isBlazor()) {
4240
+ parent.notify('toolbar', { prop: 'refresh-main-toolbar', onPropertyChange: false });
4241
+ }
4242
+ }
4243
+ };
4244
+ Selection.prototype.getCurrentFlipState = function () {
4245
+ var parent = this.parent;
4246
+ if (parent.rotateFlipColl.length !== 0) {
4247
+ var totalPannedInternalPoint = extend({}, parent.panPoint.totalPannedInternalPoint, {}, true);
4248
+ parent.notify('draw', { prop: 'callUpdateCurrTransState', onPropertyChange: false });
4249
+ parent.panPoint.totalPannedInternalPoint = totalPannedInternalPoint;
4250
+ }
4251
+ else {
4252
+ parent.notify('draw', { prop: 'callUpdateCurrTransState', onPropertyChange: false });
4253
+ }
4254
+ };
4255
+ Selection.prototype.setTextBoxStylesToActObj = function () {
4256
+ var parent = this.parent;
4257
+ parent.activeObj.textSettings.fontFamily = parent.textArea.style.fontFamily;
4258
+ parent.activeObj.strokeSettings.strokeColor = parent.textArea.style.color !== '' ?
4259
+ this.rgbToHex(parseFloat(parent.textArea.style.color.split('(')[1].split(',')[0]), parseFloat(parent.textArea.style.color.split('(')[1].split(',')[1]), parseFloat(parent.textArea.style.color.split('(')[1].split(',')[2])) :
4260
+ parent.textArea.style.color;
4261
+ if (parent.textArea.style.fontWeight === 'bold') {
4262
+ parent.activeObj.textSettings.bold = true;
4263
+ }
4264
+ else {
4265
+ parent.activeObj.textSettings.bold = false;
4266
+ }
4267
+ if (parent.textArea.style.fontStyle === 'italic') {
4268
+ parent.activeObj.textSettings.italic = true;
4269
+ }
4270
+ else {
4271
+ parent.activeObj.textSettings.italic = false;
4272
+ }
4273
+ parent.activeObj.textSettings.fontSize = (parseFloat(parent.textArea.style.fontSize));
4274
+ };
4275
+ Selection.prototype.rgbToHex = function (r, g, b) {
4276
+ return '#' + this.componentToHex(r) + this.componentToHex(g) + this.componentToHex(b);
4277
+ };
4278
+ Selection.prototype.componentToHex = function (rgb) {
4279
+ var hex = rgb.toString(16);
4280
+ return hex.length === 1 ? '0' + hex : hex;
4281
+ };
4282
+ Selection.prototype.deleteItem = function () {
4283
+ var parent = this.parent;
4284
+ var shapeChangingArgs = {};
4285
+ var previousShapeSettings = {};
4286
+ if (this.isFhdEditing) {
4287
+ this.updateFreehandDrawColorChange();
4288
+ var prevCropObj = extend({}, parent.cropObj, {}, true);
4289
+ var object = { currObj: {} };
4290
+ parent.notify('filter', { prop: 'getCurrentObj', onPropertyChange: false, value: { object: object } });
4291
+ var prevObj = object['currObj'];
4292
+ prevObj.objColl = extend([], parent.objColl, [], true);
4293
+ prevObj.pointColl = extend([], parent.pointColl, [], true);
4294
+ prevObj.afterCropActions = extend([], parent.afterCropActions, [], true);
4295
+ var selPointCollObj = { selPointColl: null };
4296
+ parent.notify('freehand-draw', { prop: 'getSelPointColl', onPropertyChange: false,
4297
+ value: { obj: selPointCollObj } });
4298
+ prevObj.selPointColl = extend([], selPointCollObj['selPointColl'], [], true);
4299
+ var obj = { freehandDrawSelectedId: null };
4300
+ parent.notify('freehand-draw', { prop: 'getFreehandDrawSelectedId', onPropertyChange: false, value: { obj: obj } });
4301
+ parent.notify('freehand-draw', { prop: 'deleteFhd', value: { id: obj['freehandDrawSelectedId'] } });
4302
+ parent.notify('undo-redo', { prop: 'updateUndoRedoColl', onPropertyChange: false,
4303
+ value: { operation: 'deleteFreehandDrawing', previousObj: prevObj, previousObjColl: this.tempObjColl,
4304
+ previousPointColl: prevObj.pointColl, previousSelPointColl: prevObj.selPointColl,
4305
+ previousCropObj: prevCropObj, previousText: null,
4306
+ currentText: null, previousFilter: null, isCircleCrop: null } });
4307
+ parent.notify('undo-redo', { prop: 'updateCurrUrc', value: { type: 'ok' } });
4308
+ parent.notify('freehand-draw', { prop: 'resetFreehandDrawSelectedId' });
4309
+ }
4310
+ else if (parent.textArea.style.display === 'none') {
4311
+ var obj = { prevActObj: null };
4312
+ parent.notify('draw', { prop: 'getPrevActObj', onPropertyChange: false, value: { obj: obj } });
4313
+ if (obj['prevActObj']) {
4314
+ obj['prevActObj']['activePoint']['width'] = Math.abs(obj['prevActObj']['activePoint']['width']);
4315
+ obj['prevActObj']['activePoint']['height'] = Math.abs(obj['prevActObj']['activePoint']['height']);
4316
+ }
4317
+ if (obj['prevActObj'] && JSON.stringify(obj['prevActObj']) !== JSON.stringify(parent.activeObj)) {
4318
+ var index = parent.activeObj.currIndex;
4319
+ parent.notify('draw', { prop: 'performCancel', value: { isContextualToolbar: null } });
4320
+ for (var i = 0; i < parent.objColl.length; i++) {
4321
+ if (parent.objColl[i].currIndex === index) {
4322
+ parent.objColl.splice(i, 1);
4323
+ parent.notify('draw', { prop: 'render-image', value: { isMouseWheel: null } });
4324
+ break;
4325
+ }
4326
+ }
4327
+ }
4328
+ var object = { isNewPath: null };
4329
+ parent.notify('draw', { prop: 'getNewPath', value: { obj: object } });
4330
+ if (object['isNewPath']) {
4331
+ parent.notify('shape', { prop: 'refreshActiveObj', onPropertyChange: false });
4332
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
4333
+ parent.notify('draw', { prop: 'render-image', value: { isMouseWheel: null } });
4334
+ if (!isBlazor()) {
4335
+ parent.notify('toolbar', { prop: 'refresh-main-toolbar', onPropertyChange: false });
4336
+ }
4337
+ else {
4338
+ parent.updateToolbar(parent.element, 'imageLoaded');
4339
+ }
4340
+ }
4341
+ else if (parent.activeObj.shape) {
4342
+ parent.objColl.push(parent.activeObj);
4343
+ var prevCropObj = extend({}, parent.cropObj, {}, true);
4344
+ var object_2 = { currObj: {} };
4345
+ parent.notify('filter', { prop: 'getCurrentObj', onPropertyChange: false, value: { object: object_2 } });
4346
+ var prevObj = object_2['currObj'];
4347
+ prevObj.objColl = extend([], parent.objColl, [], true);
4348
+ prevObj.pointColl = extend([], parent.pointColl, [], true);
4349
+ prevObj.afterCropActions = extend([], parent.afterCropActions, [], true);
4350
+ var selPointCollObj = { selPointColl: null };
4351
+ parent.notify('freehand-draw', { prop: 'getSelPointColl', onPropertyChange: false,
4352
+ value: { obj: selPointCollObj } });
4353
+ prevObj.selPointColl = extend([], selPointCollObj['selPointColl'], [], true);
4354
+ parent.objColl.pop();
4355
+ previousShapeSettings = this.updatePrevShapeSettings();
4356
+ shapeChangingArgs = { action: 'delete', previousShapeSettings: previousShapeSettings, currentShapeSettings: null };
4357
+ parent.notify('shape', { prop: 'setKeyHistory', onPropertyChange: false, value: { keyHistory: '' } });
4358
+ parent.clearSelection();
4359
+ if (isBlazor() && parent.events && parent.events.shapeChanging.hasDelegate === true) {
4360
+ parent.dotNetRef.invokeMethodAsync('ShapeEventAsync', 'OnShape', shapeChangingArgs);
4361
+ }
4362
+ else {
4363
+ parent.trigger('shapeChanging', shapeChangingArgs);
4364
+ if (!isBlazor()) {
4365
+ parent.notify('toolbar', { prop: 'refresh-main-toolbar', onPropertyChange: false });
4366
+ }
4367
+ }
4368
+ if (!isNullOrUndefined(prevObj.objColl[prevObj.objColl.length - 1].currIndex)) {
4369
+ parent.notify('undo-redo', { prop: 'updateUndoRedoColl', onPropertyChange: false,
4370
+ value: { operation: 'deleteObj', previousObj: prevObj, previousObjColl: this.tempObjColl,
4371
+ previousPointColl: prevObj.pointColl, previousSelPointColl: prevObj.selPointColl,
4372
+ previousCropObj: prevCropObj, previousText: null,
4373
+ currentText: null, previousFilter: null, isCircleCrop: null } });
4374
+ parent.notify('undo-redo', { prop: 'updateCurrUrc', value: { type: 'ok' } });
4375
+ }
4376
+ }
4377
+ parent.notify('draw', { prop: 'setPrevActObj', onPropertyChange: false, value: { prevActObj: null } });
4378
+ }
4379
+ if (document.getElementById(parent.element.id + '_quickAccessToolbarArea')) {
4380
+ document.getElementById(parent.element.id + '_quickAccessToolbarArea').style.display = 'none';
4381
+ }
4382
+ };
4383
+ Selection.prototype.updateFreehandDrawColorChange = function () {
4384
+ var parent = this.parent;
4385
+ var indexObj = { freehandSelectedIndex: null };
4386
+ parent.notify('freehand-draw', { prop: 'getFreehandSelectedIndex', onPropertyChange: false, value: { obj: indexObj } });
4387
+ if (!isNullOrUndefined(indexObj['freehandSelectedIndex']) && !isNullOrUndefined(parent.pointColl[indexObj['freehandSelectedIndex']])
4388
+ && parent.pointColl[indexObj['freehandSelectedIndex']].strokeColor === '#42a5f5') {
4389
+ var obj = { tempFreeHandDrawEditingStyles: null };
4390
+ parent.notify('freehand-draw', { prop: 'getTempFreeHandDrawEditingStyles', value: { obj: obj } });
4391
+ parent.pointColl[indexObj['freehandSelectedIndex']].strokeColor = obj['tempFreeHandDrawEditingStyles'].strokeColor;
4392
+ }
4393
+ };
4394
+ Selection.prototype.updatePrevShapeSettings = function (obj) {
4395
+ var parent = this.parent;
4396
+ var fontStyle = [];
4397
+ if (parent.activeObj.shape === 'text' && parent.activeObj.textSettings) {
4398
+ if (parent.activeObj.textSettings.bold) {
4399
+ fontStyle.push('bold');
4400
+ }
4401
+ if (parent.activeObj.textSettings.italic) {
4402
+ fontStyle.push('italic');
4403
+ }
4404
+ if (parent.activeObj.textSettings.underline) {
4405
+ fontStyle.push('underline');
4406
+ }
4407
+ }
4408
+ var shapeSettingsObj = {
4409
+ id: !isNullOrUndefined(parent.activeObj.currIndex) ? parent.activeObj.currIndex : null,
4410
+ type: parent.toPascalCase(parent.activeObj.shape),
4411
+ startX: parent.activeObj.activePoint.startX, startY: parent.activeObj.activePoint.startY,
4412
+ width: parent.activeObj.activePoint.width, height: parent.activeObj.activePoint.height,
4413
+ strokeColor: parent.activeObj.strokeSettings ? parent.activeObj.strokeSettings.strokeColor : null,
4414
+ strokeWidth: parent.activeObj.strokeSettings ? parent.activeObj.strokeSettings.strokeWidth : null,
4415
+ fillColor: parent.activeObj.strokeSettings ? parent.activeObj.strokeSettings.fillColor : null,
4416
+ radius: parent.activeObj.shape === 'ellipse' ? parent.activeObj.activePoint.width / 2 : null,
4417
+ length: parent.activeObj.shape === 'line' || parent.activeObj.shape === 'arrow' ? parent.activeObj.activePoint.width : null,
4418
+ text: parent.activeObj.shape === 'text' ? (parent.activeObj.keyHistory ? parent.activeObj.keyHistory : null) : null,
4419
+ fontSize: parent.activeObj.shape === 'text' ? (parent.activeObj.textSettings ? parent.activeObj.textSettings.fontSize : null) : null,
4420
+ fontStyle: parent.activeObj.shape === 'text' ? fontStyle : null,
4421
+ color: parent.activeObj.shape === 'text' ? (parent.activeObj.strokeSettings ? parent.activeObj.strokeSettings.strokeColor : null) : null
4422
+ };
4423
+ if (obj) {
4424
+ obj['shapeSettingsObj'] = shapeSettingsObj;
4425
+ }
4426
+ return shapeSettingsObj;
4427
+ };
4428
+ Selection.prototype.getRectanglePoints = function (rectX, rectY, rectWidth, rectHeight, rectAngle, pointX, pointY) {
4429
+ var centerX = rectX + rectWidth / 2;
4430
+ var centerY = rectY + rectHeight / 2;
4431
+ var angleRad = rectAngle * (Math.PI / 180);
4432
+ var cosAngle = Math.cos(angleRad);
4433
+ var sinAngle = Math.sin(angleRad);
4434
+ var localX = pointX - centerX;
4435
+ var localY = pointY - centerY;
4436
+ var rotatedX = localX * cosAngle + localY * sinAngle;
4437
+ var rotatedY = -localX * sinAngle + localY * cosAngle;
4438
+ var halfWidth = rectWidth / 2;
4439
+ var halfHeight = rectHeight / 2;
4440
+ // Check if the rotated point is within the bounds of the rectangle
4441
+ if (rotatedX >= -halfWidth && rotatedX <= halfWidth && rotatedY >= -halfHeight &&
4442
+ rotatedY <= halfHeight) {
4443
+ return true; // Point is inside the rotated rectangle
4444
+ }
4445
+ else {
4446
+ return false; // Point is outside the rotated rectangle
4447
+ }
4448
+ };
4449
+ Selection.prototype.getTransRotationPoint = function (obj, object) {
4450
+ var rotationCirclePoint;
4451
+ var degree;
4452
+ var isHorizontalflip = false;
4453
+ var isVerticalflip = false;
4454
+ if (obj.shapeDegree === 0) {
4455
+ degree = this.parent.transform.degree;
4456
+ }
4457
+ else {
4458
+ degree = this.parent.transform.degree - obj.shapeDegree;
4459
+ }
4460
+ if (degree < 0) {
4461
+ degree = 360 + degree;
4462
+ }
4463
+ for (var i = 0; i < obj.flipObjColl.length; i++) {
4464
+ if (obj.flipObjColl[i].toLowerCase() === 'horizontal') {
4465
+ isHorizontalflip = true;
4466
+ }
4467
+ else if (obj.flipObjColl[i].toLowerCase() === 'vertical') {
4468
+ isVerticalflip = true;
4469
+ }
4470
+ }
4471
+ if (degree === 0 || degree === 360) {
4472
+ if (isVerticalflip) {
4473
+ rotationCirclePoint = { x: obj.topCenterCircle.startX,
4474
+ y: obj.topCenterCircle.startY - obj.rotationCircleLine };
4475
+ }
4476
+ else {
4477
+ rotationCirclePoint = { x: obj.bottomCenterCircle.startX,
4478
+ y: obj.bottomCenterCircle.startY + obj.rotationCircleLine };
4479
+ }
4480
+ }
4481
+ else if (degree === 90 || degree === -270) {
4482
+ if (isHorizontalflip) {
4483
+ rotationCirclePoint = { x: obj.centerRightCircle.startX +
4484
+ obj.rotationCircleLine, y: obj.centerLeftCircle.startY };
4485
+ }
4486
+ else {
4487
+ rotationCirclePoint = { x: obj.centerLeftCircle.startX -
4488
+ obj.rotationCircleLine, y: obj.centerLeftCircle.startY };
4489
+ }
4490
+ }
4491
+ else if (degree === 180 || degree === -180) {
4492
+ if (isVerticalflip) {
4493
+ rotationCirclePoint = { x: obj.bottomCenterCircle.startX,
4494
+ y: obj.bottomCenterCircle.startY + obj.rotationCircleLine };
4495
+ }
4496
+ else {
4497
+ rotationCirclePoint = { x: obj.topCenterCircle.startX,
4498
+ y: obj.topCenterCircle.startY - obj.rotationCircleLine };
4499
+ }
4500
+ }
4501
+ else if (degree === 270 || degree === -90) {
4502
+ if (isHorizontalflip) {
4503
+ rotationCirclePoint = { x: obj.centerLeftCircle.startX -
4504
+ obj.rotationCircleLine, y: obj.centerLeftCircle.startY };
4505
+ }
4506
+ else {
4507
+ rotationCirclePoint = { x: obj.centerRightCircle.startX +
4508
+ obj.rotationCircleLine, y: obj.centerLeftCircle.startY };
4509
+ }
4510
+ }
4511
+ if (object) {
4512
+ object['rotationCirclePoint'] = rotationCirclePoint;
4513
+ }
4514
+ return rotationCirclePoint;
4515
+ };
4516
+ return Selection;
4517
+ }());
4518
+ export { Selection };