@syncfusion/ej2-image-editor 20.4.51 → 21.1.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/.eslintrc.json +1 -0
  2. package/CHANGELOG.md +55 -5
  3. package/dist/ej2-image-editor.umd.min.js +2 -2
  4. package/dist/ej2-image-editor.umd.min.js.map +1 -1
  5. package/dist/es6/ej2-image-editor.es2015.js +20032 -11350
  6. package/dist/es6/ej2-image-editor.es2015.js.map +1 -1
  7. package/dist/es6/ej2-image-editor.es5.js +20027 -11313
  8. package/dist/es6/ej2-image-editor.es5.js.map +1 -1
  9. package/dist/global/ej2-image-editor.min.js +2 -2
  10. package/dist/global/ej2-image-editor.min.js.map +1 -1
  11. package/dist/global/index.d.ts +1 -1
  12. package/package.json +12 -12
  13. package/src/image-editor/action/crop.d.ts +36 -0
  14. package/src/image-editor/action/crop.js +829 -0
  15. package/src/image-editor/action/draw.d.ts +125 -0
  16. package/src/image-editor/action/draw.js +3263 -0
  17. package/src/image-editor/action/export.d.ts +23 -0
  18. package/src/image-editor/action/export.js +364 -0
  19. package/src/image-editor/action/filter.d.ts +35 -0
  20. package/src/image-editor/action/filter.js +699 -0
  21. package/src/image-editor/action/freehand-draw.d.ts +61 -0
  22. package/src/image-editor/action/freehand-draw.js +1015 -0
  23. package/src/image-editor/action/index.d.ts +9 -0
  24. package/src/image-editor/action/index.js +9 -0
  25. package/src/image-editor/action/selection.d.ts +139 -0
  26. package/src/image-editor/action/selection.js +4518 -0
  27. package/src/image-editor/action/shape.d.ts +94 -0
  28. package/src/image-editor/action/shape.js +2745 -0
  29. package/src/image-editor/action/transform.d.ts +67 -0
  30. package/src/image-editor/action/transform.js +1859 -0
  31. package/src/image-editor/action/undo-redo.d.ts +43 -0
  32. package/src/image-editor/action/undo-redo.js +800 -0
  33. package/src/image-editor/base/enum.d.ts +189 -0
  34. package/src/image-editor/base/enum.js +198 -0
  35. package/src/image-editor/base/image-editor-model.d.ts +626 -0
  36. package/src/image-editor/base/image-editor.d.ts +1300 -0
  37. package/src/image-editor/base/image-editor.js +2270 -0
  38. package/src/image-editor/base/index.d.ts +4 -0
  39. package/src/image-editor/base/index.js +2 -0
  40. package/src/image-editor/base/interface.d.ts +1128 -0
  41. package/src/image-editor/base/interface.js +1 -0
  42. package/src/image-editor/index.d.ts +3 -5
  43. package/src/image-editor/index.js +3 -4
  44. package/src/image-editor/renderer/index.d.ts +1 -0
  45. package/src/image-editor/renderer/index.js +1 -0
  46. package/src/image-editor/renderer/toolbar.d.ts +105 -0
  47. package/src/image-editor/renderer/toolbar.js +3018 -0
  48. package/styles/bootstrap-dark.css +79 -8
  49. package/styles/bootstrap.css +79 -8
  50. package/styles/bootstrap4.css +79 -8
  51. package/styles/bootstrap5-dark.css +81 -11
  52. package/styles/bootstrap5.css +81 -11
  53. package/styles/fabric-dark.css +79 -8
  54. package/styles/fabric.css +79 -8
  55. package/styles/fluent-dark.css +79 -8
  56. package/styles/fluent.css +79 -8
  57. package/styles/highcontrast-light.css +81 -10
  58. package/styles/highcontrast.css +82 -10
  59. package/styles/image-editor/_highcontrast-definition.scss +1 -1
  60. package/styles/image-editor/_highcontrast-light-definition.scss +1 -1
  61. package/styles/image-editor/_layout.scss +28 -18
  62. package/styles/image-editor/_material3-dark-definition.scss +1 -0
  63. package/styles/image-editor/_material3-definition.scss +10 -10
  64. package/styles/image-editor/_theme.scss +11 -6
  65. package/styles/image-editor/bootstrap-dark.css +79 -8
  66. package/styles/image-editor/bootstrap.css +79 -8
  67. package/styles/image-editor/bootstrap4.css +79 -8
  68. package/styles/image-editor/bootstrap5-dark.css +81 -11
  69. package/styles/image-editor/bootstrap5.css +81 -11
  70. package/styles/image-editor/fabric-dark.css +79 -8
  71. package/styles/image-editor/fabric.css +79 -8
  72. package/styles/image-editor/fluent-dark.css +79 -8
  73. package/styles/image-editor/fluent.css +79 -8
  74. package/styles/image-editor/highcontrast-light.css +81 -10
  75. package/styles/image-editor/highcontrast.css +82 -10
  76. package/styles/image-editor/icons/_bootstrap-dark.scss +132 -0
  77. package/styles/image-editor/icons/_bootstrap.scss +132 -0
  78. package/styles/image-editor/icons/_bootstrap4.scss +132 -0
  79. package/styles/image-editor/icons/_bootstrap5.scss +132 -0
  80. package/styles/image-editor/icons/_fabric-dark.scss +132 -0
  81. package/styles/image-editor/icons/_fabric.scss +132 -0
  82. package/styles/image-editor/icons/_fluent.scss +132 -0
  83. package/styles/image-editor/icons/_fusionnew.scss +132 -0
  84. package/styles/image-editor/icons/_highcontrast-light.scss +132 -0
  85. package/styles/image-editor/icons/_highcontrast.scss +132 -0
  86. package/styles/image-editor/icons/_material-dark.scss +132 -0
  87. package/styles/image-editor/icons/_material.scss +132 -0
  88. package/styles/image-editor/icons/_material3-dark.scss +1 -0
  89. package/styles/image-editor/icons/_material3.scss +133 -1
  90. package/styles/image-editor/icons/_tailwind.scss +132 -0
  91. package/styles/image-editor/material-dark.css +79 -16
  92. package/styles/image-editor/material.css +79 -11
  93. package/styles/image-editor/material3-dark.css +453 -0
  94. package/styles/image-editor/material3-dark.scss +14 -0
  95. package/styles/image-editor/material3.css +509 -0
  96. package/styles/image-editor/material3.scss +14 -0
  97. package/styles/image-editor/tailwind-dark.css +79 -8
  98. package/styles/image-editor/tailwind.css +79 -8
  99. package/styles/material-dark.css +79 -16
  100. package/styles/material.css +79 -11
  101. package/styles/material3-dark.css +453 -0
  102. package/styles/material3-dark.scss +3 -0
  103. package/styles/material3.css +509 -0
  104. package/styles/material3.scss +3 -0
  105. package/styles/tailwind-dark.css +79 -8
  106. package/styles/tailwind.css +79 -8
  107. package/GitLeaksReport.json +0 -1
  108. package/gitleaks-ci/gitleaks +0 -0
  109. package/gitleaks-ci.tar.gz +0 -0
  110. package/src/image-editor/image-editor-model.d.ts +0 -331
  111. package/src/image-editor/image-editor.d.ts +0 -1428
  112. package/src/image-editor/image-editor.js +0 -12849
@@ -0,0 +1,829 @@
1
+ import { extend, isBlazor, isNullOrUndefined } from '@syncfusion/ej2-base';
2
+ var Crop = /** @class */ (function () {
3
+ function Crop(parent) {
4
+ this.croppedDegree = 0; // Specifies the degree when crop is performed
5
+ this.cropDestPoints = { startX: 0, startY: 0, width: 0, height: 0 }; // To redraw old image when navigate to crop tab
6
+ this.tempFlipPanPoint = { x: 0, y: 0 };
7
+ this.isPreventScaling = false;
8
+ this.parent = parent;
9
+ this.addEventListener();
10
+ }
11
+ Crop.prototype.destroy = function () {
12
+ if (this.parent.isDestroyed) {
13
+ return;
14
+ }
15
+ this.removeEventListener();
16
+ };
17
+ Crop.prototype.addEventListener = function () {
18
+ this.parent.on('crop', this.cropping, this);
19
+ this.parent.on('destroyed', this.destroy, this);
20
+ };
21
+ Crop.prototype.removeEventListener = function () {
22
+ this.parent.off('crop', this.crop);
23
+ this.parent.off('destroyed', this.destroy);
24
+ };
25
+ Crop.prototype.cropping = function (args) {
26
+ this.updateCropPvtVar();
27
+ switch (args.prop) {
28
+ case 'cropImg':
29
+ this.cropImg(args.value['isRotateCrop']);
30
+ break;
31
+ case 'cropCircle':
32
+ this.cropCircle(args.value['context'], args.value['isSave'], args.value['isFlip']);
33
+ break;
34
+ case 'setCurrSelPoints':
35
+ this.setCurrSelPoints(args.value['isSetDimension']);
36
+ break;
37
+ case 'updateRotatePan':
38
+ this.updateRotatePan();
39
+ break;
40
+ case 'crop':
41
+ this.crop(args.value['obj']);
42
+ break;
43
+ case 'calcRatio':
44
+ this.calcRatio(args.value['obj']);
45
+ break;
46
+ case 'isObjInImage':
47
+ this.isObjInImage(args.value['obj'], args.value['object']);
48
+ break;
49
+ case 'getCurrFlipState':
50
+ this.getCurrFlipState(args.value['panObj']);
51
+ break;
52
+ case 'setPreviousCropCurrentObj':
53
+ this.prevCropCurrObj = args.value['obj'];
54
+ break;
55
+ case 'setCropDestPoints':
56
+ this.cropDestPoints = args.value['point'];
57
+ break;
58
+ case 'getTempFlipPanPoint':
59
+ args.value['obj']['point'] = this.tempFlipPanPoint;
60
+ break;
61
+ case 'setTempFlipPanPoint':
62
+ if (isNullOrUndefined(args.value['isAdd'])) {
63
+ this.tempFlipPanPoint = args.value['point'];
64
+ }
65
+ else {
66
+ this.tempFlipPanPoint.x += args.value['point'].x;
67
+ this.tempFlipPanPoint.y += args.value['point'].y;
68
+ }
69
+ break;
70
+ case 'getPreventScaling':
71
+ args.value['obj']['bool'] = this.isPreventScaling;
72
+ break;
73
+ case 'reset':
74
+ this.reset();
75
+ break;
76
+ }
77
+ };
78
+ Crop.prototype.getModuleName = function () {
79
+ return 'crop';
80
+ };
81
+ Crop.prototype.updateCropPvtVar = function () {
82
+ var parent = this.parent;
83
+ if (parent.lowerCanvas) {
84
+ this.lowerContext = parent.lowerCanvas.getContext('2d');
85
+ }
86
+ if (parent.upperCanvas) {
87
+ this.upperContext = parent.upperCanvas.getContext('2d');
88
+ }
89
+ };
90
+ Crop.prototype.reset = function () {
91
+ this.prevCropCurrObj = null;
92
+ this.croppedDegree = 0;
93
+ this.cropDestPoints = { startX: 0, startY: 0, width: 0, height: 0 };
94
+ this.tempFlipPanPoint = { x: 0, y: 0 };
95
+ this.isPreventScaling = false;
96
+ };
97
+ Crop.prototype.cropImg = function (isRotateCrop) {
98
+ var parent = this.parent;
99
+ var isNullCrop = isNullOrUndefined(isRotateCrop);
100
+ var actPoint = parent.activeObj.activePoint;
101
+ parent.notify('draw', { prop: 'setImageEdited', onPropertyChange: false });
102
+ if (isNullCrop) {
103
+ this.croppedDegree = parent.transform.degree;
104
+ }
105
+ if (isNullCrop && parent.transform.degree !== 0) {
106
+ this.updateCropObj();
107
+ var point = { startX: parent.img.destLeft, startY: parent.img.destTop, width: parent.img.destWidth,
108
+ height: parent.img.destHeight };
109
+ parent.notify('transform', { prop: 'setCurrDestinationPoint', onPropertyChange: false, value: { point: point } });
110
+ this.rotateCrop();
111
+ }
112
+ else if (isNullCrop && parent.transform.currFlipState !== '') {
113
+ this.updateCropObj();
114
+ var point = { startX: parent.img.destLeft, startY: parent.img.destTop, width: parent.img.destWidth,
115
+ height: parent.img.destHeight };
116
+ parent.notify('transform', { prop: 'setCurrDestinationPoint', onPropertyChange: false, value: { point: point } });
117
+ this.flipCrop();
118
+ }
119
+ else {
120
+ parent.notify('draw', { prop: 'setTempZoomFactor', onPropertyChange: false, value: { tempZoomFactor: parent.transform.zoomFactor } });
121
+ var ratio = this.calcRatio();
122
+ if (isNullCrop || !isRotateCrop) { // isRotateCrop is NULL or False
123
+ this.updateCropObj();
124
+ parent.notify('draw', { prop: 'resetPanPoints', onPropertyChange: false });
125
+ parent.notify('shape', { prop: 'updImgRatioForActObj', onPropertyChange: false });
126
+ var point = { startX: parent.img.destLeft, startY: parent.img.destTop, width: parent.img.destWidth,
127
+ height: parent.img.destHeight };
128
+ parent.notify('transform', { prop: 'setCurrDestinationPoint', onPropertyChange: false, value: { point: point } });
129
+ parent.currSelectionPoint = extend({}, parent.activeObj, {}, true);
130
+ this.cropDestPoints = { startX: parent.img.destLeft, startY: parent.img.destTop, width: parent.img.destWidth,
131
+ height: parent.img.destHeight };
132
+ }
133
+ var obj = { width: 0, height: 0 };
134
+ parent.notify('transform', { prop: 'calcMaxDimension', onPropertyChange: false,
135
+ value: { width: actPoint.width * ratio.width,
136
+ height: actPoint.height * ratio.height, obj: obj } });
137
+ var maxDimension = obj;
138
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
139
+ this.lowerContext.clearRect(0, 0, parent.lowerCanvas.width, parent.lowerCanvas.height);
140
+ parent.img.srcLeft = (actPoint.startX * ratio.width) - (parent.img.destLeft * ratio.width);
141
+ parent.img.srcTop = (actPoint.startY * ratio.height) - (parent.img.destTop * ratio.height);
142
+ parent.img.srcWidth = (actPoint.width * ratio.width);
143
+ parent.img.srcHeight = (actPoint.height * ratio.height);
144
+ parent.img.destLeft = (parent.lowerCanvas.clientWidth - maxDimension.width) / 2;
145
+ parent.img.destTop = (parent.lowerCanvas.clientHeight - maxDimension.height) / 2;
146
+ parent.img.destWidth = maxDimension.width;
147
+ parent.img.destHeight = maxDimension.height;
148
+ var temp = this.lowerContext.filter;
149
+ parent.notify('finetune', { prop: 'updateBrightFilter', onPropertyChange: false });
150
+ 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);
151
+ this.lowerContext.filter = 'none';
152
+ var activeObj = extend({}, parent.activeObj, {}, true);
153
+ this.cropObjColl();
154
+ parent.notify('shape', { prop: 'zoomObjColl', onPropertyChange: false, value: { isPreventApply: null } });
155
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
156
+ if (this.isObjInImage(parent.objColl[i])) {
157
+ parent.notify('shape', { prop: 'apply', onPropertyChange: false,
158
+ value: { shape: parent.objColl[i].shape, obj: parent.objColl[i], canvas: null } });
159
+ parent.notify('shape', { prop: 'refreshActiveObj', onPropertyChange: false });
160
+ }
161
+ }
162
+ parent.activeObj = activeObj;
163
+ this.cropFreehandDrawColl();
164
+ parent.notify('freehand-draw', { prop: 'zoomFHDColl', onPropertyChange: false, value: { isPreventApply: null } });
165
+ parent.notify('draw', { prop: 'clearOuterCanvas', onPropertyChange: false, value: { context: this.lowerContext } });
166
+ parent.notify('draw', { prop: 'clearOuterCanvas', onPropertyChange: false, value: { context: this.upperContext } });
167
+ if (parent.currSelectionPoint.shape === 'crop-circle') {
168
+ this.cropCircle(this.lowerContext);
169
+ }
170
+ else {
171
+ parent.isCircleCrop = false;
172
+ }
173
+ this.lowerContext.filter = temp;
174
+ parent.notify('shape', { prop: 'refreshActiveObj', onPropertyChange: false });
175
+ parent.currObjType.isCustomCrop = false;
176
+ parent.pan(false);
177
+ parent.transform.defaultZoomFactor = 0;
178
+ }
179
+ };
180
+ Crop.prototype.updateCropObj = function () {
181
+ this.parent.afterCropActions = [];
182
+ var object = { currObj: {} };
183
+ this.parent.notify('filter', { prop: 'getCurrentObj', onPropertyChange: false, value: { object: object } });
184
+ var obj = object['currObj'];
185
+ this.parent.cropObj = extend({}, obj, {}, true);
186
+ };
187
+ Crop.prototype.rotateCrop = function () {
188
+ var parent = this.parent;
189
+ var shape = parent.activeObj.shape || '';
190
+ var tempDegree = parent.transform.degree;
191
+ parent.notify('shape', { prop: 'updImgRatioForActObj', onPropertyChange: false });
192
+ parent.currSelectionPoint = extend({}, parent.activeObj, {}, true);
193
+ parent.objColl.push(parent.activeObj);
194
+ parent.activeObj = extend({}, parent.objColl[parent.objColl.length - 1], {}, true);
195
+ this.lowerContext.setTransform(1, 0, 0, 1, 0, 0);
196
+ parent.notify('draw', { prop: 'setClientTransDim', onPropertyChange: false,
197
+ value: { isPreventDimension: null } });
198
+ this.lowerContext.clearRect(0, 0, parent.lowerCanvas.width, parent.lowerCanvas.height);
199
+ parent.transform.degree = 0;
200
+ var temp = this.lowerContext.filter;
201
+ parent.notify('finetune', { prop: 'updateBrightFilter', onPropertyChange: false });
202
+ 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);
203
+ this.lowerContext.filter = temp;
204
+ var length = 0;
205
+ if (tempDegree === 90 || tempDegree === -270) {
206
+ length = 3;
207
+ }
208
+ else if (tempDegree === 180 || tempDegree === -180) {
209
+ length = 2;
210
+ }
211
+ else if (tempDegree === 270 || tempDegree === -90) {
212
+ length = 1;
213
+ }
214
+ for (var i = 0; i < length; i++) {
215
+ parent.notify('shape', { prop: 'rotateObjColl', onPropertyChange: false });
216
+ parent.notify('freehand-draw', { prop: 'rotateFhdColl', onPropertyChange: false });
217
+ }
218
+ var activeObj = extend({}, parent.objColl[parent.objColl.length - 1], {}, true);
219
+ if (parent.transform.currFlipState !== '') {
220
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
221
+ parent.objColl[i].shapeFlip = '';
222
+ }
223
+ for (var i = 0; i < parent.freehandCounter; i++) {
224
+ parent.pointColl[i].shapeFlip = '';
225
+ }
226
+ parent.transform.degree = tempDegree;
227
+ var flipState = this.getCurrCropState('initial');
228
+ parent.transform.degree = 0;
229
+ parent.notify('shape', { prop: 'redrawObj', onPropertyChange: false, value: { degree: flipState } });
230
+ parent.notify('freehand-draw', { prop: 'flipFHDColl', onPropertyChange: false,
231
+ value: { value: flipState } });
232
+ }
233
+ parent.notify('shape', { prop: 'zoomObjColl', onPropertyChange: false, value: { isPreventApply: null } });
234
+ parent.notify('freehand-draw', { prop: 'zoomFHDColl', onPropertyChange: false, value: { isPreventApply: null } });
235
+ activeObj = extend({}, parent.objColl[parent.objColl.length - 1], {}, true);
236
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
237
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'duplicate', obj: activeObj } });
238
+ parent.objColl.pop();
239
+ parent.transform.degree = 0;
240
+ this.cropImg(true);
241
+ parent.notify('transform', { prop: 'setReverseRotate', onPropertyChange: false, value: { bool: true } });
242
+ this.lowerContext.setTransform(1, 0, 0, 1, 0, 0);
243
+ parent.transform.degree = tempDegree;
244
+ parent.notify('draw', { prop: 'setDestPoints', onPropertyChange: false });
245
+ parent.notify('draw', { prop: 'currTransState', onPropertyChange: false,
246
+ value: { type: 'initial', isPreventDestination: null, context: null, isPreventCircleCrop: null } });
247
+ parent.notify('finetune', { prop: 'updateBrightFilter', onPropertyChange: false });
248
+ 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);
249
+ this.lowerContext.filter = temp;
250
+ parent.notify('draw', { prop: 'currTransState', onPropertyChange: false,
251
+ value: { type: 'reverse', isPreventDestination: null, context: null, isPreventCircleCrop: null } });
252
+ length = 0;
253
+ if (tempDegree === 90 || tempDegree === -270) {
254
+ length = 1;
255
+ }
256
+ else if (tempDegree === 180 || tempDegree === -180) {
257
+ length = 2;
258
+ }
259
+ else if (tempDegree === 270 || tempDegree === -90) {
260
+ length = 3;
261
+ }
262
+ for (var i = 0; i < length; i++) {
263
+ parent.notify('shape', { prop: 'rotateObjColl', onPropertyChange: false });
264
+ parent.notify('freehand-draw', { prop: 'rotateFhdColl', onPropertyChange: false });
265
+ }
266
+ if (this.getCurrFlipState() !== '') {
267
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
268
+ parent.objColl[i].shapeFlip = '';
269
+ }
270
+ for (var i = 0; i < parent.freehandCounter; i++) {
271
+ parent.pointColl[i].shapeFlip = '';
272
+ }
273
+ var flipState = this.getCurrCropState('reverse');
274
+ parent.notify('shape', { prop: 'redrawObj', onPropertyChange: false, value: { degree: flipState } });
275
+ parent.notify('freehand-draw', { prop: 'flipFHDColl', onPropertyChange: false,
276
+ value: { value: flipState } });
277
+ }
278
+ parent.notify('transform', { prop: 'setReverseRotate', onPropertyChange: false, value: { bool: false } });
279
+ this.lowerContext.filter = 'none';
280
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
281
+ if (this.isObjInImage(parent.objColl[i])) {
282
+ parent.notify('shape', { prop: 'apply', onPropertyChange: false,
283
+ value: { shape: parent.objColl[i].shape, obj: parent.objColl[i], canvas: null } });
284
+ parent.notify('shape', { prop: 'refreshActiveObj', onPropertyChange: false });
285
+ }
286
+ }
287
+ parent.notify('freehand-draw', { prop: 'zoomFHDColl', onPropertyChange: false, value: { isPreventApply: null } });
288
+ this.lowerContext.filter = temp;
289
+ parent.notify('draw', { prop: 'clearOuterCanvas', onPropertyChange: false, value: { context: this.lowerContext } });
290
+ parent.notify('draw', { prop: 'clearOuterCanvas', onPropertyChange: false, value: { context: this.upperContext } });
291
+ if (shape === 'crop-circle') {
292
+ this.cropCircle(this.lowerContext);
293
+ }
294
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
295
+ parent.notify('draw', { prop: 'resetPanPoints', onPropertyChange: false });
296
+ };
297
+ Crop.prototype.flipCrop = function () {
298
+ var parent = this.parent;
299
+ parent.notify('transform', { prop: 'setReverseFlip', onPropertyChange: false, value: { isReverseFlip: true } });
300
+ parent.panPoint.totalPannedPoint.x += this.tempFlipPanPoint.x;
301
+ parent.panPoint.totalPannedPoint.y += this.tempFlipPanPoint.y;
302
+ var tempCurrFlipState = parent.transform.currFlipState;
303
+ var obj = { flipColl: null };
304
+ parent.notify('transform', { prop: 'getFlipColl', onPropertyChange: false, value: { obj: obj } });
305
+ var tempFlipColl = obj['flipColl'];
306
+ parent.notify('transform', { prop: 'setFlipColl', onPropertyChange: false, value: { flipColl: [] } });
307
+ parent.notify('shape', { prop: 'updImgRatioForActObj', onPropertyChange: false });
308
+ parent.objColl.push(parent.activeObj);
309
+ if (parent.transform.zoomFactor > 0) {
310
+ var zoomFactor = parent.transform.zoomFactor;
311
+ var isUndoRedo = parent.isUndoRedo;
312
+ for (var i = 0; i < (zoomFactor * 10); i++) {
313
+ parent.isUndoRedo = true;
314
+ parent.notify('transform', { prop: 'zoomAction', onPropertyChange: false,
315
+ value: { zoomFactor: -0.1, zoomPoint: null } });
316
+ }
317
+ parent.isUndoRedo = isUndoRedo;
318
+ parent.notify('draw', { prop: 'resetPanPoints', onPropertyChange: false });
319
+ }
320
+ parent.currSelectionPoint = extend({}, parent.objColl[parent.objColl.length - 1], {}, true);
321
+ this.lowerContext.clearRect(0, 0, parent.lowerCanvas.width, parent.lowerCanvas.height);
322
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
323
+ var temp = this.lowerContext.filter;
324
+ parent.notify('finetune', { prop: 'updateBrightFilter', onPropertyChange: false });
325
+ 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);
326
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
327
+ parent.objColl[i].shapeFlip = '';
328
+ }
329
+ for (var i = 0; i < parent.freehandCounter; i++) {
330
+ parent.pointColl[i].shapeFlip = '';
331
+ }
332
+ parent.notify('shape', { prop: 'redrawObj', onPropertyChange: false, value: { degree: this.getCurrFlipState() } });
333
+ parent.notify('freehand-draw', { prop: 'flipFHDColl', onPropertyChange: false,
334
+ value: { value: this.getCurrFlipState() } });
335
+ parent.activeObj = extend({}, parent.objColl[parent.objColl.length - 1], {}, true);
336
+ parent.objColl.pop();
337
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
338
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'duplicate' } });
339
+ this.cropImg(true);
340
+ parent.notify('transform', { prop: 'setReverseRotate', onPropertyChange: false, value: { bool: true } });
341
+ this.lowerContext.setTransform(1, 0, 0, 1, 0, 0);
342
+ parent.notify('draw', { prop: 'setDestPoints', onPropertyChange: false });
343
+ parent.notify('draw', { prop: 'currTransState', onPropertyChange: false,
344
+ value: { type: 'initial', isPreventDestination: null, context: null, isPreventCircleCrop: null } });
345
+ parent.notify('finetune', { prop: 'updateBrightFilter', onPropertyChange: false });
346
+ 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);
347
+ this.lowerContext.filter = temp;
348
+ parent.notify('draw', { prop: 'setRotateZoom', onPropertyChange: false, value: { isRotateZoom: false } });
349
+ parent.notify('draw', { prop: 'currTransState', onPropertyChange: false,
350
+ value: { type: 'reverse', isPreventDestination: null, context: null, isPreventCircleCrop: null } });
351
+ parent.transform.currFlipState = tempCurrFlipState;
352
+ parent.notify('transform', { prop: 'setFlipColl', onPropertyChange: false, value: { flipColl: tempFlipColl } });
353
+ this.lowerContext.filter = 'none';
354
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
355
+ parent.objColl[i].shapeFlip = '';
356
+ }
357
+ for (var i = 0; i < parent.freehandCounter; i++) {
358
+ parent.pointColl[i].shapeFlip = '';
359
+ }
360
+ parent.notify('shape', { prop: 'redrawObj', onPropertyChange: false, value: { degree: this.getCurrFlipState() } });
361
+ parent.notify('freehand-draw', { prop: 'flipFHDColl', onPropertyChange: false,
362
+ value: { value: this.getCurrFlipState() } });
363
+ parent.notify('shape', { prop: 'zoomObjColl', onPropertyChange: false, value: { isPreventApply: null } });
364
+ parent.notify('freehand-draw', { prop: 'zoomFHDColl', onPropertyChange: false, value: { isPreventApply: null } });
365
+ this.lowerContext.filter = temp;
366
+ if ((parent.currSelectionPoint && parent.currSelectionPoint.shape === 'crop-circle') || parent.isCircleCrop) {
367
+ this.cropCircle(this.lowerContext);
368
+ }
369
+ parent.notify('shape', { prop: 'refreshActiveObj', onPropertyChange: false });
370
+ parent.notify('draw', { prop: 'clearOuterCanvas', onPropertyChange: false, value: { context: this.lowerContext } });
371
+ parent.notify('draw', { prop: 'clearOuterCanvas', onPropertyChange: false, value: { context: this.upperContext } });
372
+ this.upperContext.clearRect(0, 0, parent.upperCanvas.width, parent.upperCanvas.height);
373
+ parent.notify('transform', { prop: 'setReverseFlip', onPropertyChange: false, value: { isReverseFlip: false } });
374
+ parent.notify('draw', { prop: 'resetPanPoints', onPropertyChange: false });
375
+ this.tempFlipPanPoint = { x: 0, y: 0 };
376
+ };
377
+ Crop.prototype.cropObjColl = function () {
378
+ var parent = this.parent;
379
+ var point;
380
+ var activePoint;
381
+ var shape;
382
+ if (parent.objColl.length > 0) {
383
+ for (var i = 0, len = parent.objColl.length; i < len; i++) {
384
+ point = parent.objColl[i].activePoint;
385
+ activePoint = parent.activeObj.activePoint;
386
+ shape = parent.objColl[i].shape;
387
+ parent.objColl[i].imageRatio = { startX: ((point.startX - activePoint.startX) / activePoint.width),
388
+ startY: ((point.startY - activePoint.startY) / activePoint.height),
389
+ endX: ((point.endX - activePoint.startX) / activePoint.width),
390
+ endY: ((point.endY - activePoint.startY) / activePoint.height),
391
+ width: activePoint.width / point.width,
392
+ height: activePoint.height / point.height };
393
+ var degree = void 0;
394
+ var size = void 0;
395
+ switch (shape) {
396
+ case 'text':
397
+ if (parent.objColl[i].shapeDegree === 0) {
398
+ degree = this.parent.transform.degree;
399
+ }
400
+ else {
401
+ degree = this.parent.transform.degree - parent.objColl[i].shapeDegree;
402
+ }
403
+ size = (degree === 0 || Math.abs(degree) === 180) ? point.width : point.height;
404
+ parent.objColl[i].textSettings.fontRatio = size / parent.objColl[i].textSettings.fontSize;
405
+ break;
406
+ case 'line':
407
+ case 'arrow':
408
+ this.cropPointCollection(i);
409
+ if (shape === 'arrow') {
410
+ parent.notify('shape', { prop: 'updateArrowRatio', onPropertyChange: false, value: { obj: parent.objColl[i] } });
411
+ }
412
+ break;
413
+ case 'path':
414
+ this.cropPointCollection(i);
415
+ break;
416
+ }
417
+ }
418
+ }
419
+ };
420
+ Crop.prototype.cropPointCollection = function (i) {
421
+ var parent = this.parent;
422
+ var shape = parent.objColl[i].shape;
423
+ var x;
424
+ var y;
425
+ var width;
426
+ var height;
427
+ var point = parent.activeObj.activePoint;
428
+ if (shape === 'path') {
429
+ x = point.startX;
430
+ y = point.startY;
431
+ width = point.width;
432
+ height = point.height;
433
+ }
434
+ else {
435
+ x = parent.img.destLeft;
436
+ y = parent.img.destTop;
437
+ width = parent.img.destWidth;
438
+ height = parent.img.destHeight;
439
+ }
440
+ var selPoint = parent.objColl[i];
441
+ for (var n = 0, len = selPoint.pointColl.length; n < len; n++) {
442
+ selPoint.pointColl[n].ratioX =
443
+ (selPoint.pointColl[n].x - x) / width;
444
+ selPoint.pointColl[n].ratioY =
445
+ (selPoint.pointColl[n].y - y) / height;
446
+ }
447
+ };
448
+ Crop.prototype.cropFreehandDrawColl = function () {
449
+ var parent = this.parent;
450
+ // Update crop values to point collection
451
+ for (var n = 0; n < parent.freehandCounter; n++) {
452
+ parent.points = extend([], parent.pointColl[n].points, []);
453
+ parent.notify('freehand-draw', { prop: 'setPointCounter', onPropertyChange: false, value: { value: 0 } });
454
+ var len = parent.points.length;
455
+ for (var l = 0; l < len; l++) {
456
+ parent.points[l].ratioX = (parent.points[l].x -
457
+ parent.activeObj.activePoint.startX) / parent.activeObj.activePoint.width;
458
+ parent.points[l].ratioY = (parent.points[l].y -
459
+ parent.activeObj.activePoint.startY) / parent.activeObj.activePoint.height;
460
+ }
461
+ }
462
+ parent.notify('freehand-draw', { prop: 'updateCropPtsForSel', onPropertyChange: false });
463
+ };
464
+ Crop.prototype.setCurrSelPoints = function (isSetDimension) {
465
+ var parent = this.parent;
466
+ var destPoint = this.cropDestPoints;
467
+ parent.img.srcLeft = 0;
468
+ parent.img.srcTop = 0;
469
+ parent.img.srcWidth = parent.baseImg.width;
470
+ parent.img.srcHeight = parent.baseImg.height;
471
+ parent.img.destLeft = destPoint.startX;
472
+ parent.img.destTop = destPoint.startY;
473
+ parent.img.destWidth = destPoint.width;
474
+ parent.img.destHeight = destPoint.height;
475
+ this.lowerContext.clearRect(0, 0, parent.lowerCanvas.width, parent.lowerCanvas.height);
476
+ if (isSetDimension) {
477
+ parent.notify('draw', { prop: 'setDestPoints', onPropertyChange: false });
478
+ }
479
+ parent.notify('draw', { prop: 'currTransState', onPropertyChange: false,
480
+ value: { type: 'initial', isPreventDestination: null, context: null, isPreventCircleCrop: null } });
481
+ if (this.croppedDegree === 0 && parent.transform.degree === 0 && parent.currSelectionPoint
482
+ && parent.currSelectionPoint.shape !== 'crop-circle' && parent.currSelectionPoint.shape !== 'crop-square') {
483
+ parent.img.destLeft = destPoint.startX;
484
+ parent.img.destTop = destPoint.startY;
485
+ parent.img.destWidth = destPoint.width;
486
+ parent.img.destHeight = destPoint.height;
487
+ }
488
+ if (parent.transform.degree === 0) {
489
+ parent.img.destLeft += parent.panPoint.totalPannedInternalPoint.x;
490
+ parent.img.destTop += parent.panPoint.totalPannedInternalPoint.y;
491
+ }
492
+ parent.notify('filter', { prop: 'updateBrightFilter', onPropertyChange: false });
493
+ 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);
494
+ parent.notify('draw', { prop: 'currTransState', onPropertyChange: false,
495
+ value: { type: 'reverse', isPreventDestination: null, context: null, isPreventCircleCrop: true } });
496
+ if (parent.cropObj.activeObj.shape) {
497
+ var destPoints = { startX: parent.img.destLeft, startY: parent.img.destTop, width: parent.img.destWidth,
498
+ height: parent.img.destHeight };
499
+ if (parent.currSelectionPoint && parent.currSelectionPoint.activePoint) {
500
+ parent.img.destLeft = parent.currSelectionPoint.activePoint.startX;
501
+ parent.img.destTop = parent.currSelectionPoint.activePoint.startY;
502
+ parent.img.destWidth = parent.currSelectionPoint.activePoint.width;
503
+ parent.img.destHeight = parent.currSelectionPoint.activePoint.height;
504
+ }
505
+ parent.notify('shape', { prop: 'zoomObjColl', onPropertyChange: false, value: { isPreventApply: null } });
506
+ parent.notify('freehand-draw', { prop: 'zoomFHDColl', onPropertyChange: false, value: { isPreventApply: null } });
507
+ parent.img.destLeft = destPoints.startX;
508
+ parent.img.destTop = destPoints.startY;
509
+ parent.img.destWidth = destPoints.width;
510
+ parent.img.destHeight = destPoints.height;
511
+ parent.notify('freehand-draw', { prop: 'updateFHDColl', onPropertyChange: false });
512
+ var cropObjColl = extend([], parent.objColl, null, true);
513
+ var cropPointColl = extend([], parent.pointColl, null, true);
514
+ parent.objColl = [];
515
+ parent.pointColl = [];
516
+ parent.freehandCounter = 0;
517
+ var object = { selPointColl: null };
518
+ parent.notify('freehand-draw', { prop: 'getSelPointColl', onPropertyChange: false,
519
+ value: { obj: object } });
520
+ var cropSelPointColl = object['selPointColl'];
521
+ parent.notify('freehand-draw', { prop: 'setSelPointColl', onPropertyChange: false,
522
+ value: { obj: { selPointColl: [] } } });
523
+ parent.cropObj.filter = this.lowerContext.filter;
524
+ parent.notify('draw', { prop: 'setCurrentObj', onPropertyChange: false, value: { obj: null } });
525
+ var activeObj = extend({}, parent.activeObj, null, true);
526
+ parent.notify('shape', { prop: 'refreshActiveObj', onPropertyChange: false });
527
+ parent.objColl = cropObjColl;
528
+ parent.pointColl = cropPointColl;
529
+ parent.freehandCounter = parent.pointColl.length;
530
+ parent.notify('freehand-draw', { prop: 'setSelPointColl', onPropertyChange: false,
531
+ value: { obj: { selPointColl: cropSelPointColl } } });
532
+ parent.notify('shape', { prop: 'iterateObjColl', onPropertyChange: false });
533
+ parent.notify('freehand-draw', { prop: 'freehandRedraw', onPropertyChange: false,
534
+ value: { context: this.lowerContext, points: null } });
535
+ parent.notify('freehand-draw', { prop: 'updateFHDColl', onPropertyChange: false });
536
+ parent.notify('shape', { prop: 'zoomObjColl', onPropertyChange: false, value: { isPreventApply: null } });
537
+ parent.notify('freehand-draw', { prop: 'zoomFHDColl', onPropertyChange: false, value: { isPreventApply: null } });
538
+ parent.currSelectionPoint = null;
539
+ if (parent.transform.degree === 0) {
540
+ parent.notify('transform', { prop: 'drawPannImage', onPropertyChange: false,
541
+ value: { point: { x: 0, y: 0 } } });
542
+ }
543
+ parent.activeObj = activeObj;
544
+ parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'duplicate' } });
545
+ parent.notify('transform', { prop: 'setTempPanMove', onPropertyChange: false,
546
+ value: { point: null } });
547
+ }
548
+ else {
549
+ var temp = this.lowerContext.filter;
550
+ this.lowerContext.filter = 'none';
551
+ parent.notify('shape', { prop: 'iterateObjColl', onPropertyChange: false });
552
+ parent.notify('freehand-draw', { prop: 'freehandRedraw', onPropertyChange: false,
553
+ value: { context: this.lowerContext, points: null } });
554
+ this.lowerContext.filter = temp;
555
+ parent.currSelectionPoint = null;
556
+ }
557
+ };
558
+ Crop.prototype.cropCircle = function (context, isSave, isFlip) {
559
+ var parent = this.parent;
560
+ if (isFlip && parent.transform.currFlipState !== '') {
561
+ parent.notify('draw', { prop: 'setTransform', onPropertyChange: false,
562
+ value: { context: context, value: parent.transform.currFlipState, isReverse: null } });
563
+ }
564
+ context.globalCompositeOperation = 'destination-in';
565
+ context.beginPath();
566
+ var centerX = isNullOrUndefined(isSave) ? parent.img.destLeft + (parent.img.destWidth / 2) : parent.img.destWidth / 2;
567
+ var centerY = isNullOrUndefined(isSave) ? parent.img.destTop + (parent.img.destHeight / 2) : parent.img.destHeight / 2;
568
+ var radius = parent.img.destWidth / 2;
569
+ context.arc(centerX, centerY, radius, 0, Math.PI * 2);
570
+ context.closePath();
571
+ context.fill();
572
+ context.restore();
573
+ context.globalCompositeOperation = 'source-over';
574
+ parent.currObjType.isActiveObj = parent.isCircleCrop = true;
575
+ if (isFlip && parent.transform.currFlipState !== '') {
576
+ parent.notify('draw', { prop: 'setTransform', onPropertyChange: false,
577
+ value: { context: context, value: parent.transform.currFlipState, isReverse: null } });
578
+ }
579
+ };
580
+ Crop.prototype.getCurrCropState = function (type, isAllowInvert) {
581
+ var parent = this.parent;
582
+ var flipState = '';
583
+ var state = [];
584
+ var obj = { flipColl: null };
585
+ parent.notify('transform', { prop: 'getFlipColl', onPropertyChange: false, value: { obj: obj } });
586
+ if (type === 'initial') {
587
+ if (Math.abs(parent.transform.degree) === 180) {
588
+ flipState = obj['flipColl'].length > 1 ? this.getCurrFlipState() : parent.transform.currFlipState;
589
+ }
590
+ else {
591
+ for (var i = 0, len = parent.rotateFlipColl.length; i < len; i++) {
592
+ if (typeof (parent.rotateFlipColl[i]) === 'number') {
593
+ state.push('number');
594
+ }
595
+ else if (typeof (parent.rotateFlipColl[i]) === 'string') {
596
+ state.push('string');
597
+ }
598
+ }
599
+ if (state.length > 1 && state[state.length - 1] === 'string' && state[state.length - 2] === 'number') {
600
+ if (parent.transform.currFlipState === 'horizontal') {
601
+ flipState = 'vertical';
602
+ }
603
+ else if (parent.transform.currFlipState === 'vertical') {
604
+ flipState = 'horizontal';
605
+ }
606
+ }
607
+ else if (state.length > 1 && state[state.length - 1] === 'number' && state[state.length - 2] === 'string') {
608
+ flipState = obj['flipColl'].length > 1 ? this.getCurrFlipState() : parent.transform.currFlipState;
609
+ }
610
+ }
611
+ }
612
+ else {
613
+ flipState = this.getCurrFlipState();
614
+ if (isAllowInvert || !this.isInitialRotate()) {
615
+ if (parent.transform.degree === -90 || parent.transform.degree === -270) {
616
+ if (flipState === 'horizontal') {
617
+ flipState = 'vertical';
618
+ }
619
+ else if (flipState === 'vertical') {
620
+ flipState = 'horizontal';
621
+ }
622
+ }
623
+ }
624
+ }
625
+ if (flipState === '') {
626
+ flipState = obj['flipColl'].length > 1 ? this.getCurrFlipState() : parent.transform.currFlipState;
627
+ }
628
+ return flipState;
629
+ };
630
+ Crop.prototype.isInitialRotate = function () {
631
+ var isRotate = false;
632
+ if (this.parent.rotateFlipColl.length > 0 && typeof (this.parent.rotateFlipColl[0]) === 'number') {
633
+ isRotate = true;
634
+ }
635
+ return isRotate;
636
+ };
637
+ Crop.prototype.updateRotatePan = function () {
638
+ var parent = this.parent;
639
+ if (isNullOrUndefined(parent.panPoint.currentPannedPoint)) {
640
+ return;
641
+ }
642
+ var panRegion = '';
643
+ if (parent.rotateFlipColl.length > 0 && typeof (parent.rotateFlipColl[0]) === 'number'
644
+ && parent.transform.degree < 0) {
645
+ panRegion = this.getCurrCropState('reverse', true);
646
+ }
647
+ else {
648
+ panRegion = this.getCurrFlipState();
649
+ }
650
+ if (parent.transform.degree % 90 === 0 && parent.transform.degree % 180 !== 0) {
651
+ if (parent.transform.degree === 90 || (parent.transform.degree === -90 &&
652
+ (panRegion === 'horizontal' || panRegion === 'vertical'))
653
+ || (parent.transform.degree === -270 && (panRegion === '' || panRegion === 'verticalHorizontal'
654
+ || panRegion === 'horizontalVertical'))) {
655
+ if (panRegion === 'horizontal' || panRegion === '') {
656
+ parent.img.destLeft += parent.panPoint.currentPannedPoint.y;
657
+ }
658
+ else {
659
+ parent.img.destLeft -= parent.panPoint.currentPannedPoint.y;
660
+ }
661
+ if (panRegion === '' || panRegion === 'vertical') {
662
+ parent.img.destTop -= parent.panPoint.currentPannedPoint.x;
663
+ }
664
+ else {
665
+ parent.img.destTop += parent.panPoint.currentPannedPoint.x;
666
+ }
667
+ }
668
+ else if (parent.transform.degree === 270 || (parent.transform.degree === -270 &&
669
+ (panRegion === 'horizontal' || panRegion === 'vertical'))
670
+ || (parent.transform.degree === -90 && (panRegion === '' || panRegion === 'verticalHorizontal'
671
+ || panRegion === 'horizontalVertical'))) {
672
+ if (panRegion === '' || panRegion === 'horizontal') {
673
+ parent.img.destLeft -= parent.panPoint.currentPannedPoint.y;
674
+ }
675
+ else {
676
+ parent.img.destLeft += parent.panPoint.currentPannedPoint.y;
677
+ }
678
+ if (panRegion === '' || panRegion === 'vertical') {
679
+ parent.img.destTop += parent.panPoint.currentPannedPoint.x;
680
+ }
681
+ else {
682
+ parent.img.destTop -= parent.panPoint.currentPannedPoint.x;
683
+ }
684
+ }
685
+ }
686
+ else {
687
+ if (parent.transform.degree === 180 || parent.transform.degree === -180) {
688
+ if (panRegion === '' || panRegion === 'vertical') {
689
+ parent.img.destLeft -= parent.panPoint.currentPannedPoint.x;
690
+ }
691
+ else {
692
+ parent.img.destLeft += parent.panPoint.currentPannedPoint.x;
693
+ }
694
+ if (panRegion === '' || panRegion === 'horizontal') {
695
+ parent.img.destTop -= parent.panPoint.currentPannedPoint.y;
696
+ }
697
+ else {
698
+ parent.img.destTop += parent.panPoint.currentPannedPoint.y;
699
+ }
700
+ }
701
+ }
702
+ };
703
+ Crop.prototype.crop = function (obj) {
704
+ var _this = this;
705
+ var parent = this.parent;
706
+ if (!parent.disabled && parent.isImageLoaded) {
707
+ var object_1 = { isCropToolbar: parent.isCropToolbar };
708
+ if (parent.currObjType.isUndoAction && !object_1['isCropToolbar']) {
709
+ parent.notify('undo-redo', { prop: 'refreshUrc', value: { bool: null } });
710
+ }
711
+ var transitionArgs = { cancel: false, startPoint: { x: parent.activeObj.activePoint.startX,
712
+ y: parent.activeObj.activePoint.startY }, endPoint: { x: parent.activeObj.activePoint.endX,
713
+ y: parent.activeObj.activePoint.endY }, preventScaling: false };
714
+ if (!object_1['isCropToolbar'] && isBlazor() && parent.events && parent.events.cropping.hasDelegate === true) {
715
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
716
+ parent.dotNetRef.invokeMethodAsync('CropEventAsync', 'OnCrop', transitionArgs).then(function (args) {
717
+ _this.cropEvent(args, obj, object_1);
718
+ });
719
+ }
720
+ else {
721
+ if (!object_1['isCropToolbar']) {
722
+ parent.trigger('cropping', transitionArgs);
723
+ }
724
+ this.cropEvent(transitionArgs, obj, object_1);
725
+ }
726
+ }
727
+ };
728
+ Crop.prototype.cropEvent = function (transitionArgs, obj, object) {
729
+ var parent = this.parent;
730
+ var splitWords;
731
+ if (!transitionArgs.cancel) {
732
+ splitWords = parent.activeObj.shape ? parent.activeObj.shape.split('-') : [];
733
+ if (!parent.disabled && parent.activeObj.horTopLine && (parent.currObjType.isCustomCrop || (splitWords.length > 0 &&
734
+ splitWords[0] === 'crop'))) {
735
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
736
+ obj.isCrop = true;
737
+ var prevCropObj = extend({}, parent.cropObj, {}, true);
738
+ var prevObj = extend({}, this.prevCropCurrObj, {}, true);
739
+ if (transitionArgs.preventScaling) {
740
+ this.isPreventScaling = true;
741
+ }
742
+ else {
743
+ this.isPreventScaling = false;
744
+ }
745
+ this.cropImg();
746
+ parent.transform.zoomFactor = 0;
747
+ parent.zoomSettings.zoomFactor = 1;
748
+ parent.setProperties({ zoomSettings: { zoomFactor: 1 } }, true);
749
+ parent.notify('transform', { prop: 'setPreviousZoomValue', onPropertyChange: false,
750
+ value: { previousZoomValue: parent.zoomSettings.zoomFactor } });
751
+ var currSelPtObj = { prevCurrSelectionPoint: this.parent.prevCurrSelectionPoint };
752
+ prevObj.currSelectionPoint = extend({}, currSelPtObj['prevCurrSelectionPoint'], {}, true);
753
+ parent.notify('undo-redo', { prop: 'updateUndoRedoColl', onPropertyChange: false,
754
+ value: { operation: 'crop', previousObj: prevObj, previousObjColl: prevObj.objColl,
755
+ previousPointColl: prevObj.pointColl, previousSelPointColl: prevObj.selPointColl,
756
+ previousCropObj: prevCropObj, previousText: null,
757
+ currentText: null, previousFilter: null, isCircleCrop: parent.isCircleCrop } });
758
+ if (!object['isCropToolbar']) {
759
+ parent.notify('undo-redo', { prop: 'updateCurrUrc', value: { type: 'ok' } });
760
+ }
761
+ parent.notify('transform', { prop: 'setCropDimension', onPropertyChange: false,
762
+ value: { width: parent.cropObj.destPoints.width, height: parent.cropObj.destPoints.height } });
763
+ if (!isBlazor() && !object['isCropToolbar']) {
764
+ parent.notify('toolbar', { prop: 'refresh-toolbar', onPropertyChange: false, value: { type: 'main',
765
+ isApplyBtn: false, isCropping: false, isZooming: null, cType: null } });
766
+ }
767
+ else if (!object['isCropToolbar']) {
768
+ this.parent.updateToolbar(this.parent.element, 'imageLoaded');
769
+ }
770
+ }
771
+ }
772
+ };
773
+ Crop.prototype.calcRatio = function (obj) {
774
+ var parent = this.parent;
775
+ var widthRatio;
776
+ var heightRatio;
777
+ if (parent.transform.degree === 0 || parent.transform.degree % 180 === 0) {
778
+ widthRatio = parent.baseImg.width / parent.img.destWidth;
779
+ heightRatio = parent.baseImg.height / parent.img.destHeight;
780
+ }
781
+ else {
782
+ widthRatio = parent.baseImg.height / parent.img.destWidth;
783
+ heightRatio = parent.baseImg.width / parent.img.destHeight;
784
+ }
785
+ if (obj) {
786
+ obj['width'] = widthRatio;
787
+ obj['height'] = heightRatio;
788
+ }
789
+ return { width: widthRatio, height: heightRatio };
790
+ };
791
+ Crop.prototype.isObjInImage = function (obj, dummyObj) {
792
+ var parent = this.parent;
793
+ var isInside = false;
794
+ var startX = obj.activePoint.startX;
795
+ var endX = obj.activePoint.endX;
796
+ var startY = obj.activePoint.startY;
797
+ var endY = obj.activePoint.endY;
798
+ if ((startX >= parent.img.destLeft && endX <= (parent.img.destLeft + parent.img.destWidth)) ||
799
+ (startX <= parent.img.destLeft && endX >= parent.img.destLeft) ||
800
+ (startX <= (parent.img.destLeft + parent.img.destWidth) && endX >= (parent.img.destLeft + parent.img.destWidth)) ||
801
+ (startY >= parent.img.destTop && endY <= (parent.img.destTop + parent.img.destHeight)) ||
802
+ (startY <= parent.img.destTop && endY >= parent.img.destTop) ||
803
+ (startY <= (parent.img.destTop + parent.img.destHeight) && endY >= (parent.img.destTop + parent.img.destHeight))) {
804
+ isInside = true;
805
+ }
806
+ if (dummyObj) {
807
+ dummyObj['isInside'] = isInside;
808
+ }
809
+ return isInside;
810
+ };
811
+ Crop.prototype.getCurrFlipState = function (panObj) {
812
+ var parent = this.parent;
813
+ var obj = { panRegion: '' };
814
+ var object = { collection: parent.rotateFlipColl };
815
+ parent.notify('shape', { prop: 'alignRotateFlipColl', onPropertyChange: false,
816
+ value: { collection: parent.rotateFlipColl, isRotateFlipCollection: true, obj: object } });
817
+ parent.rotateFlipColl = object['collection'];
818
+ for (var i = 0, len = parent.rotateFlipColl.length; i < len; i++) {
819
+ parent.notify('transform', { prop: 'setCurrPanRegion', onPropertyChange: false,
820
+ value: { region: obj['panRegion'], type: parent.rotateFlipColl[i], obj: obj } });
821
+ }
822
+ if (panObj) {
823
+ panObj['panRegion'] = obj['panRegion'];
824
+ }
825
+ return obj['panRegion'];
826
+ };
827
+ return Crop;
828
+ }());
829
+ export { Crop };