@syncfusion/ej2-image-editor 21.2.6 → 22.1.34

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