@syncfusion/ej2-image-editor 21.1.35 → 21.1.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/.eslintrc.json +1 -0
  2. package/CHANGELOG.md +50 -0
  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 +19332 -12536
  6. package/dist/es6/ej2-image-editor.es2015.js.map +1 -1
  7. package/dist/es6/ej2-image-editor.es5.js +19360 -12537
  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 +36 -0
  14. package/src/image-editor/action/crop.js +829 -0
  15. package/src/image-editor/action/draw.d.ts +125 -0
  16. package/src/image-editor/action/draw.js +3263 -0
  17. package/src/image-editor/action/export.d.ts +23 -0
  18. package/src/image-editor/action/export.js +364 -0
  19. package/src/image-editor/action/filter.d.ts +35 -0
  20. package/src/image-editor/action/filter.js +699 -0
  21. package/src/image-editor/action/freehand-draw.d.ts +61 -0
  22. package/src/image-editor/action/freehand-draw.js +1015 -0
  23. package/src/image-editor/action/index.d.ts +9 -0
  24. package/src/image-editor/action/index.js +9 -0
  25. package/src/image-editor/action/selection.d.ts +139 -0
  26. package/src/image-editor/action/selection.js +4518 -0
  27. package/src/image-editor/action/shape.d.ts +94 -0
  28. package/src/image-editor/action/shape.js +2745 -0
  29. package/src/image-editor/action/transform.d.ts +67 -0
  30. package/src/image-editor/action/transform.js +1859 -0
  31. package/src/image-editor/action/undo-redo.d.ts +43 -0
  32. package/src/image-editor/action/undo-redo.js +800 -0
  33. package/src/image-editor/base/enum.d.ts +189 -0
  34. package/src/image-editor/base/enum.js +198 -0
  35. package/src/image-editor/{image-editor-model.d.ts → base/image-editor-model.d.ts} +130 -41
  36. package/src/image-editor/{image-editor.d.ts → base/image-editor.d.ts} +413 -1107
  37. package/src/image-editor/base/image-editor.js +2270 -0
  38. package/src/image-editor/base/index.d.ts +4 -0
  39. package/src/image-editor/base/index.js +2 -0
  40. package/src/image-editor/base/interface.d.ts +1128 -0
  41. package/src/image-editor/base/interface.js +1 -0
  42. package/src/image-editor/index.d.ts +3 -5
  43. package/src/image-editor/index.js +3 -4
  44. package/src/image-editor/renderer/index.d.ts +1 -0
  45. package/src/image-editor/renderer/index.js +1 -0
  46. package/src/image-editor/renderer/toolbar.d.ts +105 -0
  47. package/src/image-editor/renderer/toolbar.js +3018 -0
  48. package/styles/bootstrap-dark.css +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 +71 -5
  58. package/styles/highcontrast.css +72 -5
  59. package/styles/image-editor/_highcontrast-definition.scss +1 -1
  60. package/styles/image-editor/_highcontrast-light-definition.scss +1 -1
  61. package/styles/image-editor/_layout.scss +21 -7
  62. package/styles/image-editor/_material3-dark-definition.scss +1 -0
  63. package/styles/image-editor/_material3-definition.scss +11 -0
  64. package/styles/image-editor/_theme.scss +7 -2
  65. package/styles/image-editor/bootstrap-dark.css +69 -3
  66. package/styles/image-editor/bootstrap.css +69 -3
  67. package/styles/image-editor/bootstrap4.css +69 -3
  68. package/styles/image-editor/bootstrap5-dark.css +69 -3
  69. package/styles/image-editor/bootstrap5.css +69 -3
  70. package/styles/image-editor/fabric-dark.css +69 -3
  71. package/styles/image-editor/fabric.css +69 -3
  72. package/styles/image-editor/fluent-dark.css +69 -3
  73. package/styles/image-editor/fluent.css +69 -3
  74. package/styles/image-editor/highcontrast-light.css +71 -5
  75. package/styles/image-editor/highcontrast.css +72 -5
  76. package/styles/image-editor/icons/_bootstrap-dark.scss +132 -0
  77. package/styles/image-editor/icons/_bootstrap.scss +132 -0
  78. package/styles/image-editor/icons/_bootstrap4.scss +132 -0
  79. package/styles/image-editor/icons/_bootstrap5.scss +132 -0
  80. package/styles/image-editor/icons/_fabric-dark.scss +132 -0
  81. package/styles/image-editor/icons/_fabric.scss +132 -0
  82. package/styles/image-editor/icons/_fluent.scss +132 -0
  83. package/styles/image-editor/icons/_fusionnew.scss +132 -0
  84. package/styles/image-editor/icons/_highcontrast-light.scss +132 -0
  85. package/styles/image-editor/icons/_highcontrast.scss +132 -0
  86. package/styles/image-editor/icons/_material-dark.scss +132 -0
  87. package/styles/image-editor/icons/_material.scss +132 -0
  88. package/styles/image-editor/icons/_material3-dark.scss +1 -0
  89. package/styles/image-editor/icons/_material3.scss +133 -1
  90. package/styles/image-editor/icons/_tailwind.scss +132 -0
  91. package/styles/image-editor/material-dark.css +69 -3
  92. package/styles/image-editor/material.css +69 -3
  93. package/styles/image-editor/material3-dark.css +453 -0
  94. package/styles/image-editor/material3-dark.scss +14 -0
  95. package/styles/image-editor/material3.css +509 -0
  96. package/styles/image-editor/material3.scss +14 -0
  97. package/styles/image-editor/tailwind-dark.css +69 -3
  98. package/styles/image-editor/tailwind.css +69 -3
  99. package/styles/material-dark.css +69 -3
  100. package/styles/material.css +69 -3
  101. package/styles/material3-dark.css +453 -0
  102. package/styles/material3-dark.scss +3 -0
  103. package/styles/material3.css +509 -0
  104. package/styles/material3.scss +3 -0
  105. package/styles/tailwind-dark.css +69 -3
  106. package/styles/tailwind.css +69 -3
  107. package/src/image-editor/image-editor.js +0 -14729
@@ -0,0 +1,1015 @@
1
+ import { EventHandler, extend, isBlazor, isNullOrUndefined } from '@syncfusion/ej2-base';
2
+ var FreehandDrawing = /** @class */ (function () {
3
+ function FreehandDrawing(parent) {
4
+ this.fhdObj = { lastWidth: 0, lastVelocity: 0, time: 0, pointX: 0, pointY: 0 };
5
+ this.isFreehandDrawing = false;
6
+ this.freehandDownPoint = { x: 0, y: 0 };
7
+ this.isFreehandPointMoved = false;
8
+ this.pointCounter = 0;
9
+ // eslint-disable-next-line
10
+ this.selPointColl = {};
11
+ this.currFHDIdx = 0; // Specifies id for every freehand drawing - uses while deleting
12
+ this.selPoints = [];
13
+ this.tempFHDStyles = { strokeColor: null, fillColor: null, strokeWidth: null };
14
+ this.parent = parent;
15
+ this.addEventListener();
16
+ }
17
+ FreehandDrawing.prototype.destroy = function () {
18
+ if (this.parent.isDestroyed) {
19
+ return;
20
+ }
21
+ this.removeEventListener();
22
+ };
23
+ FreehandDrawing.prototype.addEventListener = function () {
24
+ this.parent.on('freehand-draw', this.draw, this);
25
+ this.parent.on('destroyed', this.destroy, this);
26
+ };
27
+ FreehandDrawing.prototype.removeEventListener = function () {
28
+ this.parent.off('freehand-draw', this.draw);
29
+ this.parent.off('destroyed', this.destroy);
30
+ };
31
+ FreehandDrawing.prototype.draw = function (args) {
32
+ this.updateFhdPvtVar();
33
+ switch (args.prop) {
34
+ case 'hoverFhd': {
35
+ this.hoverFhd(args.value['strokeColor'], args.value['strokeWidth']);
36
+ break;
37
+ }
38
+ case 'freehandDownHandler':
39
+ this.freehandDownHandler(args.value['e'], args.value['canvas']);
40
+ break;
41
+ case 'freehandUpHandler':
42
+ this.freehandUpHandler(args.value['e'], args.value['canvas'], args.value['context']);
43
+ break;
44
+ case 'handle-freehand-draw': {
45
+ var id = parseInt(args.value['id'].split('_')[1], 10) - 1;
46
+ if (this.isFHDIdx(id)) {
47
+ this.deleteFhd(id, true);
48
+ }
49
+ break;
50
+ }
51
+ case 'freehandRedraw':
52
+ this.freehandRedraw(args.value['context'], args.value['points']);
53
+ break;
54
+ case 'deleteFhd': {
55
+ var id = parseInt(args.value['id'].split('_')[1], 10) - 1;
56
+ this.deleteFhd(id, true);
57
+ break;
58
+ }
59
+ case 'selectFhd': {
60
+ var id = null;
61
+ if (args.value['id']) {
62
+ id = parseInt(args.value['id'].split('_')[1], 10) - 1;
63
+ }
64
+ this.selectFhd(id);
65
+ break;
66
+ }
67
+ case 'applyFhd':
68
+ this.applyFhd();
69
+ break;
70
+ case 'cancelFhd':
71
+ this.cancelFhd();
72
+ break;
73
+ case 'updateFHDCurPts':
74
+ this.updateFHDCurPts();
75
+ break;
76
+ case 'rotateFhdColl':
77
+ this.rotateFhdColl();
78
+ break;
79
+ case 'flipFHDColl':
80
+ this.flipFHDColl(args.value['value']);
81
+ break;
82
+ case 'panFHDColl':
83
+ this.panFHDColl(args.value['xDiff'], args.value['yDiff'], args.value['panRegion']);
84
+ break;
85
+ case 'updateFHDColl':
86
+ this.updateFHDColl();
87
+ break;
88
+ case 'zoomFHDColl':
89
+ this.zoomFHDColl(args.value['isPreventApply']);
90
+ break;
91
+ case 'apply-pen-draw':
92
+ this.applyPenDraw();
93
+ break;
94
+ case 'freeHandDraw':
95
+ this.freeHandDraw(args.value['value']);
96
+ break;
97
+ case 'isFHDIdx':
98
+ this.isFHDIdx(args.value['index'], args.value['obj']);
99
+ break;
100
+ case 'getSqPtFD':
101
+ this.getSqPtFD(args.value['idx'], args.value['obj']);
102
+ break;
103
+ case 'getSelPointColl':
104
+ args.value['obj']['selPointColl'] = extend([], this.selPointColl);
105
+ break;
106
+ case 'setSelPointColl':
107
+ this.selPointColl = extend([], args.value['obj']['selPointColl']);
108
+ break;
109
+ case 'setFreehandDrawHoveredIndex':
110
+ this.fhdHovIdx = args.value['index'];
111
+ break;
112
+ case 'getFreehandDrawHoveredIndex':
113
+ args.value['obj']['index'] = this.fhdHovIdx;
114
+ break;
115
+ case 'setPointCounter':
116
+ this.pointCounter = args.value['value'];
117
+ break;
118
+ case 'getPenStrokeWidth':
119
+ args.value['obj']['penStrokeWidth'] = this.penStrokeWidth;
120
+ break;
121
+ case 'setPenStrokeWidth':
122
+ this.penStrokeWidth = args.value['value'];
123
+ break;
124
+ case 'getCurrentFreehandDrawIndex':
125
+ args.value['obj']['currentFreehandDrawIndex'] = this.currFHDIdx;
126
+ break;
127
+ case 'setCurrentFreehandDrawIndex':
128
+ this.currFHDIdx = args.value['value'];
129
+ break;
130
+ case 'updateCropPtsForSel':
131
+ this.updateCropPtsForSel();
132
+ break;
133
+ case 'getFreehandDrawSelectedId':
134
+ args.value['obj']['freehandDrawSelectedId'] = this.fhdSelID;
135
+ break;
136
+ case 'resetFreehandDrawSelectedId':
137
+ this.fhdSelID = null;
138
+ break;
139
+ case 'getTempFreeHandDrawEditingStyles':
140
+ args.value['obj']['tempFreeHandDrawEditingStyles'] = this.tempFHDStyles;
141
+ break;
142
+ case 'setFreehandSelectedIndex':
143
+ this.fhdSelIdx = args.value['index'];
144
+ break;
145
+ case 'getFreehandSelectedIndex':
146
+ args.value['obj']['freehandSelectedIndex'] = this.fhdSelIdx;
147
+ break;
148
+ case 'reset':
149
+ this.reset();
150
+ break;
151
+ }
152
+ };
153
+ FreehandDrawing.prototype.updateFhdPvtVar = function () {
154
+ var parent = this.parent;
155
+ if (parent.lowerCanvas) {
156
+ this.lowerContext = parent.lowerCanvas.getContext('2d');
157
+ }
158
+ if (parent.upperCanvas) {
159
+ this.upperContext = parent.upperCanvas.getContext('2d');
160
+ }
161
+ };
162
+ FreehandDrawing.prototype.reset = function () {
163
+ this.fhdObj = { lastWidth: 0, lastVelocity: 0, time: 0, pointX: 0, pointY: 0 };
164
+ this.isFreehandDrawing = this.isFreehandPointMoved = false;
165
+ this.selPoints = [];
166
+ this.freehandDownPoint = { x: 0, y: 0 };
167
+ this.selPointColl = {};
168
+ this.fhdHovIdx = null;
169
+ this.pointCounter = 0;
170
+ this.fhdSelID = null;
171
+ this.penStrokeWidth = undefined;
172
+ this.currFHDIdx = 0;
173
+ this.fhdSelIdx = null;
174
+ this.tempFHDStyles = { strokeColor: null, fillColor: null, strokeWidth: null };
175
+ };
176
+ FreehandDrawing.prototype.getModuleName = function () {
177
+ return 'freehand-draw';
178
+ };
179
+ FreehandDrawing.prototype.hoverFhd = function (fillStyle, strokeWidth) {
180
+ var parent = this.parent;
181
+ parent.lowerCanvas = document.querySelector('#' + parent.element.id + '_lowerCanvas');
182
+ this.lowerContext = parent.lowerCanvas.getContext('2d');
183
+ parent.upperCanvas = document.querySelector('#' + parent.element.id + '_upperCanvas');
184
+ this.upperContext = parent.upperCanvas.getContext('2d');
185
+ var context = this.upperContext;
186
+ var idx = -1;
187
+ if (this.fhdHovIdx > -1) {
188
+ idx = this.fhdHovIdx;
189
+ }
190
+ else {
191
+ idx = this.fhdSelIdx;
192
+ }
193
+ parent.points = extend([], parent.pointColl[idx].points);
194
+ this.pointCounter = 0;
195
+ var len = parent.points.length;
196
+ var controlPoint1;
197
+ var controlPoint2;
198
+ var startPoint;
199
+ var endPoint;
200
+ var minStrokeWidth = 0;
201
+ var maxStrokeWidth = 0;
202
+ context.fillStyle = fillStyle ? fillStyle : parent.pointColl[idx].strokeColor;
203
+ context.strokeStyle = context.fillStyle;
204
+ minStrokeWidth = maxStrokeWidth = this.penStrokeWidth = strokeWidth ?
205
+ strokeWidth : parent.pointColl[idx].strokeWidth;
206
+ if (len === 1) {
207
+ controlPoint1 = controlPoint2 = startPoint = endPoint = parent.points[0];
208
+ this.startDraw(context, controlPoint1, controlPoint2, startPoint, endPoint, minStrokeWidth, maxStrokeWidth);
209
+ }
210
+ for (var l = 0; l < len - 3; l++) {
211
+ if (parent.points[l + 1] && parent.points[l + 2] && parent.points[l + 2]) {
212
+ controlPoint1 = (this.calcCurveCP(parent.points[l + 0], parent.points[l + 1], parent.points[l + 2])).controlPoint2;
213
+ controlPoint2 = (this.calcCurveCP(parent.points[l + 1], parent.points[l + 2], parent.points[l + 3])).controlPoint1;
214
+ startPoint = parent.points[l + 1];
215
+ endPoint = parent.points[l + 2];
216
+ this.startDraw(context, controlPoint1, controlPoint2, startPoint, endPoint, minStrokeWidth, maxStrokeWidth);
217
+ }
218
+ }
219
+ context.closePath();
220
+ // Outer selection
221
+ var point = this.getSqPtFD(idx);
222
+ var tempLineWidth = context.lineWidth;
223
+ context.lineWidth = 2;
224
+ context.strokeStyle = parent.themeColl[parent.theme]['primaryColor'];
225
+ context.beginPath();
226
+ context.rect(point.startX, point.startY, point.width, point.height);
227
+ context.stroke();
228
+ context.closePath();
229
+ context.lineWidth = tempLineWidth;
230
+ };
231
+ FreehandDrawing.prototype.freehandDownHandler = function (e, canvas) {
232
+ this.parent.lowerCanvas = document.querySelector('#' + this.parent.element.id + '_lowerCanvas');
233
+ this.lowerContext = this.parent.lowerCanvas.getContext('2d');
234
+ this.parent.upperCanvas = document.querySelector('#' + this.parent.element.id + '_upperCanvas');
235
+ this.upperContext = this.parent.upperCanvas.getContext('2d');
236
+ this.fhdObj.time = new Date().getTime();
237
+ this.isFreehandDrawing = true;
238
+ if (e.type === 'mousedown') {
239
+ this.freehandDownPoint = { x: e.clientX, y: e.clientY };
240
+ }
241
+ else {
242
+ this.freehandDownPoint = { x: e.touches[0].clientX, y: e.touches[0].clientY };
243
+ }
244
+ this.isFreehandPointMoved = false;
245
+ EventHandler.add(canvas, 'mousemove touchmove', this.freehandMoveHandler, this);
246
+ };
247
+ FreehandDrawing.prototype.freehandUpHandler = function (e, canvas, context) {
248
+ var rect = canvas.getBoundingClientRect();
249
+ var parent = this.parent;
250
+ EventHandler.remove(canvas, 'mousemove touchmove', this.freehandMoveHandler);
251
+ if (parent.points.length === 0) {
252
+ if (e.type === 'mouseup') {
253
+ this.processPoint(e.clientX - rect.left, e.clientY - rect.top, true, context);
254
+ }
255
+ else {
256
+ if (!this.isFreehandPointMoved) {
257
+ this.processPoint(this.freehandDownPoint.x - rect.left, this.freehandDownPoint.y - rect.top, true, context);
258
+ }
259
+ }
260
+ }
261
+ context.closePath();
262
+ var prevCropObj = extend({}, parent.cropObj, {}, true);
263
+ var object = { currObj: {} };
264
+ parent.notify('filter', { prop: 'getCurrentObj', onPropertyChange: false, value: { object: object } });
265
+ var prevObj = object['currObj'];
266
+ prevObj.objColl = extend([], parent.objColl, [], true);
267
+ prevObj.pointColl = extend([], parent.pointColl, [], true);
268
+ prevObj.afterCropActions = extend([], parent.afterCropActions, [], true);
269
+ var selPointCollObj = { selPointColl: null };
270
+ parent.notify('freehand-draw', { prop: 'getSelPointColl', onPropertyChange: false,
271
+ value: { obj: selPointCollObj } });
272
+ prevObj.selPointColl = extend([], selPointCollObj['selPointColl'], [], true);
273
+ var fhCnt = parent.freehandCounter;
274
+ parent.pointColl[fhCnt] = {};
275
+ parent.pointColl[fhCnt].points = extend([], parent.points);
276
+ parent.pointColl[fhCnt].strokeColor = parent.activeObj.strokeSettings.strokeColor;
277
+ parent.pointColl[fhCnt].strokeWidth = this.penStrokeWidth;
278
+ parent.pointColl[fhCnt].flipState = parent.transform.currFlipState;
279
+ parent.pointColl[fhCnt].id = 'pen_' + (this.currFHDIdx + 1);
280
+ parent.points = [];
281
+ this.selPointColl[fhCnt] = {};
282
+ this.selPointColl[fhCnt].points = extend([], this.selPoints);
283
+ this.selPoints = [];
284
+ this.pointCounter = 0;
285
+ parent.freehandCounter++;
286
+ this.currFHDIdx++;
287
+ this.isFreehandDrawing = false;
288
+ parent.notify('undo-redo', { prop: 'updateUndoRedoColl', onPropertyChange: false,
289
+ value: { operation: 'freehand-draw', previousObj: prevObj, previousObjColl: prevObj.objColl,
290
+ previousPointColl: prevObj.pointColl, previousSelPointColl: prevObj.selPointColl,
291
+ previousCropObj: prevCropObj, previousText: null,
292
+ currentText: null, previousFilter: null, isCircleCrop: null } });
293
+ };
294
+ FreehandDrawing.prototype.freehandMoveHandler = function (e) {
295
+ this.isFreehandPointMoved = true;
296
+ var rect = this.parent.upperCanvas.getBoundingClientRect();
297
+ var x;
298
+ var y;
299
+ if (e.type === 'mousemove') {
300
+ x = e.clientX - rect.left;
301
+ y = e.clientY - rect.top;
302
+ }
303
+ else {
304
+ x = e.touches[0].clientX - rect.left;
305
+ y = e.touches[0].clientY - rect.top;
306
+ }
307
+ if (this.isFreehandDrawing) {
308
+ this.processPoint(x, y, false, this.upperContext);
309
+ }
310
+ };
311
+ FreehandDrawing.prototype.processPoint = function (x, y, mouseDown, context) {
312
+ var parent = this.parent;
313
+ var lastPoint = this.point(x, y, new Date().getTime());
314
+ lastPoint = parent.points.length > 0 && parent.points[parent.points.length - 1];
315
+ var isLastPointTooClose = lastPoint ? this.distanceTo(lastPoint) <= 5 : false;
316
+ var controlPoint1;
317
+ var controlPoint2;
318
+ var startPoint;
319
+ var endPoint;
320
+ this.selPoints.push({ x: x, y: y, ratioX: (x - parent.img.destLeft) / parent.img.destWidth,
321
+ ratioY: (y - parent.img.destTop) / parent.img.destHeight,
322
+ time: this.fhdObj.time });
323
+ if (!lastPoint || !(lastPoint && isLastPointTooClose) || mouseDown) {
324
+ this.fhdObj.time = new Date().getTime();
325
+ parent.points.push({ x: x, y: y, ratioX: (x - parent.img.destLeft) / parent.img.destWidth,
326
+ ratioY: (y - parent.img.destTop) / parent.img.destHeight,
327
+ time: this.fhdObj.time });
328
+ if (parent.points.length > 3) {
329
+ var p0 = parent.points[this.pointCounter];
330
+ var p1 = parent.points[this.pointCounter + 1];
331
+ var p2 = parent.points[this.pointCounter + 2];
332
+ var p3 = parent.points[this.pointCounter + 3];
333
+ controlPoint1 = this.calcCurveCP(p0, p1, p2).controlPoint2;
334
+ controlPoint2 = this.calcCurveCP(p1, p2, p3).controlPoint1;
335
+ startPoint = parent.points[this.pointCounter + 1];
336
+ endPoint = parent.points[this.pointCounter + 2];
337
+ var minStrokeWidth = 0.5;
338
+ var maxStrokeWidth = 5;
339
+ if (!isNullOrUndefined(this.penStrokeWidth)) {
340
+ minStrokeWidth = maxStrokeWidth = this.penStrokeWidth;
341
+ }
342
+ this.startDraw(context, controlPoint1, controlPoint2, startPoint, endPoint, minStrokeWidth, maxStrokeWidth);
343
+ this.pointCounter++;
344
+ }
345
+ if (mouseDown) {
346
+ controlPoint1 = controlPoint2 = startPoint = endPoint = { x: x, y: y, time: new Date().getTime() };
347
+ var minStrokeWidth = 0.5;
348
+ var maxStrokeWidth = 5;
349
+ if (!isNullOrUndefined(this.penStrokeWidth)) {
350
+ minStrokeWidth = maxStrokeWidth = this.penStrokeWidth;
351
+ }
352
+ this.startDraw(context, controlPoint1, controlPoint2, startPoint, endPoint, minStrokeWidth, maxStrokeWidth);
353
+ }
354
+ }
355
+ };
356
+ FreehandDrawing.prototype.calcCurveCP = function (p1, p2, p3) {
357
+ if (!p2) {
358
+ p2 = p1;
359
+ }
360
+ if (!p3) {
361
+ p3 = p2;
362
+ }
363
+ var dx1 = p1.x - p2.x;
364
+ var dy1 = p1.y - p2.y;
365
+ var dx2 = p2.x - p3.x;
366
+ var dy2 = p2.y - p3.y;
367
+ var m1 = { x: (p1.x + p2.x) / 2.0, y: (p1.y + p2.y) / 2.0 };
368
+ var m2 = { x: (p2.x + p3.x) / 2.0, y: (p2.y + p3.y) / 2.0 };
369
+ var l1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
370
+ var l2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
371
+ var dxm = (m1.x - m2.x);
372
+ var dym = (m1.y - m2.y);
373
+ var k = l2 / (l1 + l2);
374
+ var cm = { x: m2.x + dxm * k, y: m2.y + dym * k };
375
+ var tx = p2.x - cm.x;
376
+ var ty = p2.y - cm.y;
377
+ return {
378
+ controlPoint1: this.point(m1.x + tx, m1.y + ty, 0),
379
+ controlPoint2: this.point(m2.x + tx, m2.y + ty, 0)
380
+ };
381
+ };
382
+ FreehandDrawing.prototype.point = function (x, y, time) {
383
+ this.fhdObj.pointX = x;
384
+ this.fhdObj.pointY = y;
385
+ return { x: this.fhdObj.pointX, y: this.fhdObj.pointY, time: time };
386
+ };
387
+ FreehandDrawing.prototype.startDraw = function (context, controlPoint1, controlPoint2, startPoint, endPoint, minStrokeWidth, maxStrokeWidth) {
388
+ var tempVelocity;
389
+ tempVelocity = this.pointVelocity(startPoint);
390
+ tempVelocity = 0.7 * tempVelocity + (1 - 0.7) * this.fhdObj.lastVelocity;
391
+ var newWidth = Math.max(maxStrokeWidth / (0.7 + 1), minStrokeWidth);
392
+ this.drawCurve(this.fhdObj.time, newWidth, context, controlPoint1, controlPoint2, startPoint, endPoint, maxStrokeWidth);
393
+ this.fhdObj.lastVelocity = tempVelocity;
394
+ this.fhdObj.time = newWidth;
395
+ };
396
+ FreehandDrawing.prototype.pointVelocity = function (startPoint) {
397
+ return (this.fhdObj.time !== startPoint.time) ? this.distanceTo(startPoint) /
398
+ (this.fhdObj.time - startPoint.time) : 0;
399
+ };
400
+ FreehandDrawing.prototype.distanceTo = function (start) {
401
+ return Math.sqrt(Math.pow(this.fhdObj.pointX - start.x, 2) + Math.pow(this.fhdObj.pointY - start.y, 2));
402
+ };
403
+ FreehandDrawing.prototype.drawCurve = function (startWidth, endWidth, context, controlPoint1, controlPoint2, startPoint, endPoint, maxStrokeWidth) {
404
+ var width;
405
+ var i;
406
+ var t1;
407
+ var t2;
408
+ var t3;
409
+ var u1;
410
+ var u2;
411
+ var u3;
412
+ var x;
413
+ var y;
414
+ var widthValue = endWidth - startWidth;
415
+ var bezierLength = this.bezierLength(controlPoint1, controlPoint2, startPoint, endPoint);
416
+ var drawSteps = Math.ceil(bezierLength) * 2;
417
+ context.beginPath();
418
+ for (i = 0; i < drawSteps; i++) {
419
+ t1 = i / drawSteps;
420
+ t2 = t1 * t1;
421
+ t3 = t2 * t1;
422
+ u1 = 1 - t1;
423
+ u2 = u1 * u1;
424
+ u3 = u2 * u1;
425
+ x = u3 * startPoint.x;
426
+ x += 3 * u2 * t1 * controlPoint1.x;
427
+ x += 3 * u1 * t2 * controlPoint2.x;
428
+ x += t3 * endPoint.x;
429
+ y = u3 * startPoint.y;
430
+ y += 3 * u2 * t1 * controlPoint1.y;
431
+ y += 3 * u1 * t2 * controlPoint2.y;
432
+ y += t3 * endPoint.y;
433
+ width = Math.min(startWidth + t3 * widthValue, maxStrokeWidth);
434
+ this.drawArc(x, y, width, context);
435
+ }
436
+ context.closePath();
437
+ context.fill();
438
+ };
439
+ FreehandDrawing.prototype.bezierLength = function (controlPoint1, controlPoint2, startPoint, endPoint) {
440
+ var steps = 10;
441
+ var length = 0;
442
+ var i;
443
+ var t;
444
+ var pointX1;
445
+ var pointY1;
446
+ var pointX2;
447
+ var pointY2;
448
+ var pointX3;
449
+ var pointY3;
450
+ for (i = 0; i <= steps; i++) {
451
+ t = i / steps;
452
+ pointX1 = this.bezierPoint(t, startPoint.x, controlPoint1.x, controlPoint2.x, endPoint.x);
453
+ pointY1 = this.bezierPoint(t, startPoint.y, controlPoint1.y, controlPoint2.y, endPoint.y);
454
+ if (i > 0) {
455
+ pointX3 = pointX1 - pointX2;
456
+ pointY3 = pointY1 - pointY2;
457
+ length += Math.sqrt(pointX3 * pointX3 + pointY3 * pointY3);
458
+ }
459
+ pointX2 = pointX1;
460
+ pointY2 = pointY1;
461
+ }
462
+ return length;
463
+ };
464
+ FreehandDrawing.prototype.bezierPoint = function (t, startPoint, cp1, cp2, endPoint) {
465
+ return startPoint * (1.0 - t) * (1.0 - t) * (1.0 - t) + 3.0 * cp1 * (1.0 - t) * (1.0 - t) * t + 3.0 *
466
+ cp2 * (1.0 - t) * t * t + endPoint * t * t * t;
467
+ };
468
+ FreehandDrawing.prototype.drawArc = function (x, y, size, context) {
469
+ if ((x > this.parent.img.destLeft && y > this.parent.img.destTop && x < (this.parent.img.destLeft + this.parent.img.destWidth) &&
470
+ y < (this.parent.img.destTop + this.parent.img.destHeight) ||
471
+ (context !== this.lowerContext && context !== this.upperContext))) {
472
+ context.moveTo(x, y);
473
+ context.arc(x, y, size, 0, 2 * Math.PI, false);
474
+ }
475
+ };
476
+ FreehandDrawing.prototype.freehandRedraw = function (context, points) {
477
+ var parent = this.parent;
478
+ parent.lowerCanvas = document.querySelector('#' + parent.element.id + '_lowerCanvas');
479
+ this.lowerContext = parent.lowerCanvas.getContext('2d');
480
+ parent.upperCanvas = document.querySelector('#' + parent.element.id + '_upperCanvas');
481
+ this.upperContext = parent.upperCanvas.getContext('2d');
482
+ var temp = context.filter;
483
+ context.filter = 'none';
484
+ if (points) {
485
+ parent.pointColl[parent.freehandCounter] = {};
486
+ parent.pointColl[parent.freehandCounter].points = points;
487
+ parent.pointColl[parent.freehandCounter].strokeColor = parent.activeObj.strokeSettings.strokeColor;
488
+ parent.pointColl[parent.freehandCounter].strokeWidth = this.penStrokeWidth;
489
+ parent.pointColl[parent.freehandCounter].flipState = parent.transform.currFlipState;
490
+ parent.freehandCounter++;
491
+ }
492
+ for (var n = 0; n < parent.freehandCounter; n++) {
493
+ parent.points = extend([], parent.pointColl[n].points);
494
+ this.pointCounter = 0;
495
+ var len = parent.points.length;
496
+ var controlPoint1 = void 0;
497
+ var controlPoint2 = void 0;
498
+ var startPoint = void 0;
499
+ var endPoint = void 0;
500
+ var minStrokeWidth = void 0;
501
+ var maxStrokeWidth = void 0;
502
+ if (len > 0) {
503
+ context.fillStyle = parent.pointColl[n].strokeColor;
504
+ minStrokeWidth = maxStrokeWidth = this.penStrokeWidth = parent.pointColl[n].strokeWidth;
505
+ }
506
+ if (len === 1) {
507
+ controlPoint1 = controlPoint2 = startPoint = endPoint = parent.points[0];
508
+ this.startDraw(context, controlPoint1, controlPoint2, startPoint, endPoint, minStrokeWidth, maxStrokeWidth);
509
+ }
510
+ for (var l = 0; l < len - 3; l++) {
511
+ if (parent.points[l + 1] && parent.points[l + 2] && parent.points[l + 2]) {
512
+ controlPoint1 = (this.calcCurveCP(parent.points[l + 0], parent.points[l + 1], parent.points[l + 2])).controlPoint2;
513
+ controlPoint2 = (this.calcCurveCP(parent.points[l + 1], parent.points[l + 2], parent.points[l + 3])).controlPoint1;
514
+ startPoint = parent.points[l + 1];
515
+ endPoint = parent.points[l + 2];
516
+ this.startDraw(context, controlPoint1, controlPoint2, startPoint, endPoint, minStrokeWidth, maxStrokeWidth);
517
+ }
518
+ }
519
+ context.closePath();
520
+ }
521
+ context.filter = temp;
522
+ };
523
+ FreehandDrawing.prototype.getSqPtFD = function (idx, obj) {
524
+ var activePoint = { startX: 0, startY: 0, endX: 0, endY: 0, width: 0, height: 0 };
525
+ var sPoints = extend([], this.selPointColl[idx].points, []);
526
+ this.parent.points = extend([], this.parent.pointColl[idx].points);
527
+ this.pointCounter = 0;
528
+ var len = sPoints.length;
529
+ for (var l = 0; l < len; l++) {
530
+ if (activePoint.startX === 0 && activePoint.startY === 0 && activePoint.endX === 0 && activePoint.endY === 0) {
531
+ activePoint.startX = sPoints[l].x;
532
+ activePoint.startY = sPoints[l].y;
533
+ activePoint.endX = sPoints[l].x;
534
+ activePoint.endY = sPoints[l].y;
535
+ }
536
+ else {
537
+ activePoint.startX = Math.min(activePoint.startX, sPoints[l].x);
538
+ activePoint.startY = Math.min(activePoint.startY, sPoints[l].y);
539
+ activePoint.endX = Math.max(activePoint.endX, sPoints[l].x);
540
+ activePoint.endY = Math.max(activePoint.endY, sPoints[l].y);
541
+ }
542
+ }
543
+ activePoint.startX -= this.penStrokeWidth;
544
+ activePoint.startY -= this.penStrokeWidth;
545
+ activePoint.endX += this.penStrokeWidth;
546
+ activePoint.endY += this.penStrokeWidth;
547
+ activePoint.width = activePoint.endX - activePoint.startX;
548
+ activePoint.height = activePoint.endY - activePoint.startY;
549
+ if (obj) {
550
+ obj['activePoint'] = activePoint;
551
+ }
552
+ return activePoint;
553
+ };
554
+ FreehandDrawing.prototype.applyPenDraw = function () {
555
+ var parent = this.parent;
556
+ if (parent.currObjType.shape === 'freehanddraw') {
557
+ parent.notify('shape', { prop: 'apply', onPropertyChange: false, value: { shape: null, obj: null, canvas: null } });
558
+ parent.upperCanvas.style.cursor = parent.cursor = 'default';
559
+ parent.currObjType.shape = '';
560
+ }
561
+ parent.notify('shape', { prop: 'clearActObj' });
562
+ };
563
+ FreehandDrawing.prototype.applyFhd = function () {
564
+ var parent = this.parent;
565
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
566
+ var selectedPoint = parent.pointColl[this.fhdSelIdx];
567
+ if (selectedPoint.strokeColor === '#42a5f5') {
568
+ selectedPoint.strokeColor = this.tempFHDStyles.strokeColor;
569
+ }
570
+ if (!isBlazor()) {
571
+ parent.notify('toolbar', { prop: 'setSelectedFreehandColor', value: { color: '#42a5f5' } });
572
+ }
573
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
574
+ this.lowerContext.clearRect(0, 0, parent.lowerCanvas.width, parent.lowerCanvas.height);
575
+ parent.notify('draw', { prop: 'render-image', value: { isMouseWheel: null } });
576
+ if (!isBlazor()) {
577
+ parent.notify('toolbar', { prop: 'refresh-main-toolbar', onPropertyChange: false });
578
+ }
579
+ if (selectedPoint) {
580
+ selectedPoint.isSelected = false;
581
+ }
582
+ parent.notify('selection', { prop: 'resetFreehandDrawVariables' });
583
+ this.fhdHovIdx = this.fhdSelIdx = null;
584
+ };
585
+ FreehandDrawing.prototype.cancelFhd = function () {
586
+ var parent = this.parent;
587
+ if (!isBlazor()) {
588
+ parent.notify('toolbar', { prop: 'setSelectedFreehandColor', value: { color: '#42a5f5' } });
589
+ }
590
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
591
+ this.pointCounter = 0;
592
+ if (parent.pointColl[this.fhdSelIdx]) {
593
+ parent.pointColl[this.fhdSelIdx].strokeColor = this.tempFHDStyles.strokeColor;
594
+ parent.pointColl[this.fhdSelIdx].strokeWidth = this.tempFHDStyles.strokeWidth;
595
+ parent.pointColl[this.fhdSelIdx].isSelected = false;
596
+ }
597
+ this.fhdHovIdx = this.fhdSelIdx = this.fhdSelID = null;
598
+ parent.notify('selection', { prop: 'resetFreehandDrawVariables' });
599
+ parent.activeObj.strokeSettings.strokeColor = this.tempFHDStyles.strokeColor;
600
+ parent.activeObj.strokeSettings.strokeWidth = this.penStrokeWidth = this.tempFHDStyles.strokeWidth;
601
+ this.tempFHDStyles = { strokeColor: null, strokeWidth: null, fillColor: null };
602
+ if (!isBlazor()) {
603
+ parent.notify('toolbar', { prop: 'refresh-main-toolbar', onPropertyChange: false });
604
+ }
605
+ };
606
+ FreehandDrawing.prototype.selectFhd = function (index) {
607
+ var parent = this.parent;
608
+ parent.notify('selection', { prop: 'setFreehandDrawEditing', onPropertyChange: false, value: { bool: true } });
609
+ if (index || index === 0) {
610
+ if (this.isFHDIdx(index)) {
611
+ this.fhdSelIdx = this.fhdHovIdx = index;
612
+ this.hoverFhd();
613
+ parent.upperCanvas.style.cursor = parent.cursor = 'pointer';
614
+ }
615
+ else {
616
+ return;
617
+ }
618
+ }
619
+ this.fhdSelIdx = this.fhdHovIdx;
620
+ parent.pointColl[this.fhdSelIdx].isSelected = true;
621
+ this.fhdSelID = parent.pointColl[this.fhdSelIdx].id;
622
+ if (parent.pointColl[this.fhdHovIdx].strokeColor !== '#42a5f5') {
623
+ parent.activeObj.strokeSettings.strokeColor = this.tempFHDStyles.strokeColor =
624
+ parent.pointColl[this.fhdHovIdx].strokeColor;
625
+ }
626
+ parent.activeObj.strokeSettings.strokeWidth = this.tempFHDStyles.strokeWidth =
627
+ parent.pointColl[this.fhdHovIdx].strokeWidth;
628
+ var obj = { bool: false };
629
+ parent.notify('selection', { prop: 'getFreehandDrawEditing', onPropertyChange: false, value: { obj: obj } });
630
+ if (obj['bool']) {
631
+ if (!isBlazor()) {
632
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: { type: 'pen',
633
+ isApplyBtn: null, isCropping: null, isZooming: null, cType: null } });
634
+ }
635
+ }
636
+ else {
637
+ parent.okBtn();
638
+ }
639
+ };
640
+ FreehandDrawing.prototype.deleteFhd = function (index, isId) {
641
+ var parent = this.parent;
642
+ if (this.isFHDIdx(index)) {
643
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
644
+ // eslint-disable-next-line
645
+ var tempPointColl = extend({}, parent.pointColl, {}, true);
646
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
647
+ var tempSelPointColl = extend({}, this.selPointColl, {}, true);
648
+ parent.pointColl = {};
649
+ this.selPointColl = {};
650
+ var count = 0;
651
+ if (isNullOrUndefined(isId)) {
652
+ for (var i = 0; i < parent.freehandCounter; i++) {
653
+ if (i !== index) {
654
+ parent.pointColl[count] = tempPointColl[i];
655
+ this.selPointColl[count] = tempSelPointColl[i];
656
+ count++;
657
+ }
658
+ }
659
+ }
660
+ else {
661
+ for (var i = 0; i < parent.freehandCounter; i++) {
662
+ if (parseInt(tempPointColl[i].id.split('_')[1], 10) - 1 !== index) {
663
+ parent.pointColl[count] = tempPointColl[i];
664
+ this.selPointColl[count] = tempSelPointColl[i];
665
+ count++;
666
+ }
667
+ }
668
+ }
669
+ parent.freehandCounter -= 1;
670
+ this.fhdHovIdx = this.fhdSelIdx = null;
671
+ parent.notify('selection', { prop: 'resetFreehandDrawVariables' });
672
+ parent.notify('draw', { prop: 'render-image', value: { isMouseWheel: true } });
673
+ if (!isBlazor()) {
674
+ parent.notify('toolbar', { prop: 'refresh-main-toolbar', onPropertyChange: false });
675
+ }
676
+ }
677
+ };
678
+ FreehandDrawing.prototype.zoomX = function (x) {
679
+ return (x * this.parent.img.destWidth) + this.parent.img.destLeft;
680
+ };
681
+ FreehandDrawing.prototype.zoomY = function (y) {
682
+ return (y * this.parent.img.destHeight) + this.parent.img.destTop;
683
+ };
684
+ FreehandDrawing.prototype.zoomFHDColl = function (isPreventApply) {
685
+ var parent = this.parent;
686
+ // Updating point collection for zoom
687
+ for (var n = 0; n < parent.freehandCounter; n++) {
688
+ parent.points = extend([], parent.pointColl[n].points, []);
689
+ this.pointCounter = 0;
690
+ var len = parent.points.length;
691
+ for (var l = 0; l < len; l++) {
692
+ parent.points[l].x = this.zoomX(parent.points[l].ratioX);
693
+ parent.points[l].y = this.zoomY(parent.points[l].ratioY);
694
+ }
695
+ }
696
+ // Updating each points for cursor styles for zoom
697
+ this.updateFHDCurPts();
698
+ if (isNullOrUndefined(isPreventApply)) {
699
+ this.freehandRedraw(this.lowerContext, null);
700
+ }
701
+ };
702
+ FreehandDrawing.prototype.updateFHDCurPts = function () {
703
+ var parent = this.parent;
704
+ for (var n = 0; n < parent.freehandCounter; n++) {
705
+ if (this.selPointColl[n]) {
706
+ this.selPoints = extend([], this.selPointColl[n].points, []);
707
+ this.pointCounter = 0;
708
+ var len = this.selPoints.length;
709
+ for (var l = 0; l < len; l++) {
710
+ this.selPoints[l].x = this.zoomX(this.selPoints[l].ratioX);
711
+ this.selPoints[l].y = this.zoomY(this.selPoints[l].ratioY);
712
+ }
713
+ }
714
+ }
715
+ };
716
+ FreehandDrawing.prototype.rotateFhdColl = function () {
717
+ var parent = this.parent;
718
+ // Update rotation points for point collection
719
+ for (var n = 0; n < parent.freehandCounter; n++) {
720
+ parent.points = extend([], parent.pointColl[n].points, []);
721
+ this.pointCounter = 0;
722
+ var len = parent.points.length;
723
+ for (var l = 0; l < len; l++) {
724
+ parent.points[l].y = parent.img.destTop + (parent.img.destHeight * parent.points[l].ratioX);
725
+ parent.points[l].x = (parent.img.destLeft + parent.img.destWidth) - (parent.img.destWidth *
726
+ parent.points[l].ratioY);
727
+ parent.points[l].ratioX = (parent.points[l].x - parent.img.destLeft) / parent.img.destWidth;
728
+ parent.points[l].ratioY = (parent.points[l].y - parent.img.destTop) / parent.img.destHeight;
729
+ }
730
+ }
731
+ // Update rotation points for each point for cursor styles
732
+ for (var n = 0; n < parent.freehandCounter; n++) {
733
+ if (this.selPointColl[n]) {
734
+ this.selPoints = extend([], this.selPointColl[n].points, []);
735
+ this.pointCounter = 0;
736
+ var len = this.selPoints.length;
737
+ for (var l = 0; l < len; l++) {
738
+ this.selPoints[l].y = parent.img.destTop + (parent.img.destHeight * this.selPoints[l].ratioX);
739
+ this.selPoints[l].x = (parent.img.destLeft + parent.img.destWidth) - (parent.img.destWidth *
740
+ this.selPoints[l].ratioY);
741
+ this.selPoints[l].ratioX = (this.selPoints[l].x - parent.img.destLeft) / parent.img.destWidth;
742
+ this.selPoints[l].ratioY = (this.selPoints[l].y - parent.img.destTop) / parent.img.destHeight;
743
+ }
744
+ }
745
+ }
746
+ this.updateFHDCurPts();
747
+ };
748
+ FreehandDrawing.prototype.flipFHDColl = function (value) {
749
+ var lowercaseValue = value.toLowerCase();
750
+ if (lowercaseValue === 'horizontal') {
751
+ this.pointsHorizontalFlip();
752
+ }
753
+ else if (lowercaseValue === 'vertical') {
754
+ this.pointsVerticalFlip();
755
+ }
756
+ else {
757
+ this.pointsHorizontalFlip();
758
+ for (var i = 0; i < this.parent.freehandCounter; i++) {
759
+ this.parent.pointColl[i].shapeFlip = '';
760
+ }
761
+ this.pointsVerticalFlip();
762
+ }
763
+ };
764
+ FreehandDrawing.prototype.pointsHorizontalFlip = function () {
765
+ var parent = this.parent;
766
+ // Update flip value for point collection
767
+ for (var n = 0; n < parent.freehandCounter; n++) {
768
+ if (parent.pointColl[n].shapeFlip !== parent.transform.currFlipState) {
769
+ parent.points = extend([], parent.pointColl[n].points, []);
770
+ this.pointCounter = 0;
771
+ var len = parent.points.length;
772
+ for (var l = 0; l < len; l++) {
773
+ if (parent.points[l].x <= parent.img.destLeft + (parent.img.destWidth / 2)) {
774
+ parent.points[l].x = (parent.img.destLeft + parent.img.destWidth) - (parent.points[l].x
775
+ - parent.img.destLeft);
776
+ }
777
+ else if (parent.points[l].x >= parent.img.destLeft + (parent.img.destWidth / 2)) {
778
+ parent.points[l].x = parent.img.destLeft + (parent.img.destLeft + parent.img.destWidth -
779
+ parent.points[l].x);
780
+ }
781
+ parent.points[l].ratioX = (parent.points[l].x - parent.img.destLeft) / parent.img.destWidth;
782
+ parent.points[l].ratioY = (parent.points[l].y - parent.img.destTop) / parent.img.destHeight;
783
+ }
784
+ parent.pointColl[n].shapeFlip = parent.transform.currFlipState;
785
+ }
786
+ }
787
+ // Update flip value for each points for cursor styles
788
+ for (var n = 0; n < parent.freehandCounter; n++) {
789
+ if (this.selPointColl[n]) {
790
+ if (this.selPointColl[n].shapeFlip !== parent.transform.currFlipState) {
791
+ this.selPoints = extend([], this.selPointColl[n].points, []);
792
+ this.pointCounter = 0;
793
+ var len = this.selPoints.length;
794
+ for (var l = 0; l < len; l++) {
795
+ if (this.selPoints[l].x <= parent.img.destLeft + (parent.img.destWidth / 2)) {
796
+ this.selPoints[l].x = (parent.img.destLeft + parent.img.destWidth) - (this.selPoints[l].x -
797
+ parent.img.destLeft);
798
+ }
799
+ else if (this.selPoints[l].x >= parent.img.destLeft + (parent.img.destWidth / 2)) {
800
+ this.selPoints[l].x = parent.img.destLeft + (parent.img.destLeft + parent.img.destWidth -
801
+ this.selPoints[l].x);
802
+ }
803
+ this.selPoints[l].ratioX = (this.selPoints[l].x - parent.img.destLeft) / parent.img.destWidth;
804
+ this.selPoints[l].ratioY = (this.selPoints[l].y - parent.img.destTop) / parent.img.destHeight;
805
+ }
806
+ }
807
+ }
808
+ }
809
+ this.updateFHDCurPts();
810
+ };
811
+ FreehandDrawing.prototype.pointsVerticalFlip = function () {
812
+ var parent = this.parent;
813
+ // Update flip value for point collection
814
+ for (var n = 0; n < parent.freehandCounter; n++) {
815
+ if (parent.pointColl[n].shapeFlip !== parent.transform.currFlipState) {
816
+ parent.points = extend([], parent.pointColl[n].points, []);
817
+ this.pointCounter = 0;
818
+ var len = parent.points.length;
819
+ for (var l = 0; l < len; l++) {
820
+ if (parent.points[l].y <= parent.img.destTop + (parent.img.destHeight / 2)) {
821
+ parent.points[l].y = (parent.img.destTop + parent.img.destHeight) -
822
+ (parent.points[l].y - parent.img.destTop);
823
+ }
824
+ else if (parent.points[l].y >= parent.img.destTop + (parent.img.destHeight / 2)) {
825
+ parent.points[l].y = parent.img.destTop + (parent.img.destTop + parent.img.destHeight -
826
+ parent.points[l].y);
827
+ }
828
+ parent.points[l].ratioX = (parent.points[l].x - parent.img.destLeft) / parent.img.destWidth;
829
+ parent.points[l].ratioY = (parent.points[l].y - parent.img.destTop) / parent.img.destHeight;
830
+ }
831
+ parent.pointColl[n].shapeFlip = parent.transform.currFlipState;
832
+ }
833
+ }
834
+ // Update flip value for each points for cursor styles
835
+ for (var n = 0; n < parent.freehandCounter; n++) {
836
+ if (this.selPointColl[n]) {
837
+ if (this.selPointColl[n].shapeFlip !== parent.transform.currFlipState) {
838
+ this.selPoints = extend([], this.selPointColl[n].points, []);
839
+ this.pointCounter = 0;
840
+ var len = this.selPoints.length;
841
+ for (var l = 0; l < len; l++) {
842
+ if (this.selPoints[l].y <= parent.img.destTop + (parent.img.destHeight / 2)) {
843
+ this.selPoints[l].y = (parent.img.destTop + parent.img.destHeight) - (this.selPoints[l].y -
844
+ parent.img.destTop);
845
+ }
846
+ else if (this.selPoints[l].y >= parent.img.destTop + (parent.img.destHeight / 2)) {
847
+ this.selPoints[l].y = parent.img.destTop + (parent.img.destTop + parent.img.destHeight -
848
+ this.selPoints[l].y);
849
+ }
850
+ this.selPoints[l].ratioX = (this.selPoints[l].x - parent.img.destLeft) / parent.img.destWidth;
851
+ this.selPoints[l].ratioY = (this.selPoints[l].y - parent.img.destTop) / parent.img.destHeight;
852
+ }
853
+ }
854
+ }
855
+ }
856
+ this.updateFHDCurPts();
857
+ };
858
+ FreehandDrawing.prototype.updateFHDColl = function () {
859
+ var parent = this.parent;
860
+ for (var i = 0; i < parent.objColl.length; i++) {
861
+ parent.objColl[i].imageRatio = { startX: ((parent.objColl[i].activePoint.startX - parent.img.destLeft) /
862
+ parent.img.destWidth), startY: ((parent.objColl[i].activePoint.startY - parent.img.destTop) / parent.img.destHeight),
863
+ endX: ((parent.objColl[i].activePoint.endX - parent.img.destLeft) / parent.img.destWidth),
864
+ endY: ((parent.objColl[i].activePoint.endY - parent.img.destTop) / parent.img.destHeight),
865
+ width: parent.img.destWidth / parent.objColl[i].activePoint.width, height: parent.img.destHeight /
866
+ parent.objColl[i].activePoint.height };
867
+ if (parent.objColl[i].shape === 'path') {
868
+ for (var j = 0; j < parent.objColl[i].pointColl.length; j++) {
869
+ parent.objColl[i].pointColl[j].ratioX =
870
+ (parent.objColl[i].pointColl[j].x - parent.img.destLeft) / parent.img.destWidth;
871
+ parent.objColl[i].pointColl[j].ratioY =
872
+ (parent.objColl[i].pointColl[j].y - parent.img.destTop) / parent.img.destHeight;
873
+ }
874
+ }
875
+ parent.notify('shape', { prop: 'refreshActiveObj', onPropertyChange: false });
876
+ }
877
+ for (var n = 0; n < parent.freehandCounter; n++) {
878
+ parent.points = extend([], parent.pointColl[n].points, []);
879
+ this.pointCounter = 0;
880
+ var len = parent.points.length;
881
+ for (var l = 0; l < len; l++) {
882
+ parent.points[l].ratioX = (parent.points[l].x - parent.img.destLeft) / parent.img.destWidth;
883
+ parent.points[l].ratioY = (parent.points[l].y - parent.img.destTop) / parent.img.destHeight;
884
+ }
885
+ }
886
+ for (var n = 0; n < parent.freehandCounter; n++) {
887
+ if (this.selPointColl[n]) {
888
+ this.selPoints = extend([], this.selPointColl[n].points, []);
889
+ this.pointCounter = 0;
890
+ var len = this.selPoints.length;
891
+ for (var l = 0; l < len; l++) {
892
+ this.selPoints[l].ratioX = (this.selPoints[l].x - parent.img.destLeft) / parent.img.destWidth;
893
+ this.selPoints[l].ratioY = (this.selPoints[l].y - parent.img.destTop) / parent.img.destHeight;
894
+ }
895
+ }
896
+ }
897
+ };
898
+ FreehandDrawing.prototype.panFHDColl = function (xDiff, yDiff, panRegion) {
899
+ var parent = this.parent;
900
+ // Updating point collection for panning
901
+ for (var n = 0; n < parent.freehandCounter; n++) {
902
+ parent.points = extend([], parent.pointColl[n].points, []);
903
+ this.pointCounter = 0;
904
+ var len = parent.points.length;
905
+ for (var l = 0; l < len; l++) {
906
+ if (panRegion === '' || panRegion === 'vertical') {
907
+ parent.points[l].x += xDiff;
908
+ }
909
+ else {
910
+ parent.points[l].x -= xDiff;
911
+ }
912
+ if (panRegion === '' || panRegion === 'horizontal') {
913
+ parent.points[l].y += yDiff;
914
+ }
915
+ else {
916
+ parent.points[l].y -= yDiff;
917
+ }
918
+ }
919
+ }
920
+ // Updating each points for cursor styles for panning
921
+ for (var n = 0; n < parent.freehandCounter; n++) {
922
+ if (this.selPointColl[n]) {
923
+ this.selPoints = extend([], this.selPointColl[n].points, []);
924
+ this.pointCounter = 0;
925
+ var len = this.selPoints.length;
926
+ for (var l = 0; l < len; l++) {
927
+ if (panRegion === '' || panRegion === 'vertical') {
928
+ this.selPoints[l].x += xDiff;
929
+ }
930
+ else {
931
+ this.selPoints[l].x -= xDiff;
932
+ }
933
+ if (panRegion === '' || panRegion === 'horizontal') {
934
+ this.selPoints[l].y += yDiff;
935
+ }
936
+ else {
937
+ this.selPoints[l].y -= yDiff;
938
+ }
939
+ }
940
+ }
941
+ }
942
+ this.freehandRedraw(this.lowerContext, null);
943
+ };
944
+ FreehandDrawing.prototype.freeHandDraw = function (value) {
945
+ var parent = this.parent;
946
+ if (value) {
947
+ parent.points = [];
948
+ parent.notify('shape', { prop: 'refreshActiveObj', onPropertyChange: false });
949
+ parent.togglePen = true;
950
+ parent.upperCanvas.style.cursor = parent.cursor = 'crosshair';
951
+ parent.upperCanvas.style.display = 'block';
952
+ if (isNullOrUndefined(parent.activeObj.strokeSettings)) {
953
+ var obj = { strokeSettings: {} };
954
+ parent.notify('shape', { prop: 'getStrokeSettings', onPropertyChange: false,
955
+ value: { obj: obj } });
956
+ parent.activeObj.strokeSettings = obj['strokeSettings'];
957
+ }
958
+ if (isNullOrUndefined(parent.activeObj.strokeSettings.strokeWidth)) {
959
+ parent.activeObj.strokeSettings.strokeWidth = 4;
960
+ }
961
+ if (!isBlazor()) {
962
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: { type: 'pen',
963
+ isApplyBtn: null, isCropping: null, isZooming: null, cType: null } });
964
+ }
965
+ else {
966
+ parent.updateToolbar(parent.element, 'pen');
967
+ }
968
+ }
969
+ else {
970
+ parent.upperCanvas.style.cursor = parent.cursor = 'default';
971
+ parent.notify('shape', { prop: 'apply', onPropertyChange: false, value: { shape: null, obj: null, canvas: null } });
972
+ if (!isBlazor()) {
973
+ parent.notify('toolbar', { prop: 'refresh-main-toolbar', onPropertyChange: false });
974
+ parent.notify('toolbar', { prop: 'setCurrentToolbar', value: { type: 'main' } });
975
+ }
976
+ else {
977
+ parent.updateToolbar(parent.element, 'imageLoaded');
978
+ }
979
+ parent.notify('selection', { prop: 'setFreehandDrawCustomized', value: { isFreehandDrawCustomized: false } });
980
+ }
981
+ };
982
+ FreehandDrawing.prototype.isFHDIdx = function (index, obj) {
983
+ var isIndex = false;
984
+ for (var i = 0; i < this.parent.freehandCounter; i++) {
985
+ if (this.parent.pointColl[i].id &&
986
+ parseInt(this.parent.pointColl[i].id.split('_')[1], 10) - 1 === index) {
987
+ isIndex = true;
988
+ break;
989
+ }
990
+ }
991
+ if (obj) {
992
+ obj['isIndex'] = isIndex;
993
+ }
994
+ return isIndex;
995
+ };
996
+ FreehandDrawing.prototype.updateCropPtsForSel = function () {
997
+ var parent = this.parent;
998
+ for (var n = 0; n < parent.freehandCounter; n++) {
999
+ var obj = { selPointColl: extend([], this.selPointColl) };
1000
+ if (obj['selPointColl'][n]) {
1001
+ this.selPoints = extend([], obj['selPointColl'][n].points, []);
1002
+ this.pointCounter = 0;
1003
+ var len = this.selPoints.length;
1004
+ for (var l = 0; l < len; l++) {
1005
+ this.selPoints[l].ratioX = (this.selPoints[l].x -
1006
+ parent.activeObj.activePoint.startX) / parent.activeObj.activePoint.width;
1007
+ this.selPoints[l].ratioY = (this.selPoints[l].y -
1008
+ parent.activeObj.activePoint.startY) / parent.activeObj.activePoint.height;
1009
+ }
1010
+ }
1011
+ }
1012
+ };
1013
+ return FreehandDrawing;
1014
+ }());
1015
+ export { FreehandDrawing };