@syncfusion/ej2-image-editor 20.4.49 → 20.4.51

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.
@@ -178,9 +178,9 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
178
178
  _this.isAllowCropPan = false;
179
179
  _this.tempPannedPoint = { x: 0, y: 0 };
180
180
  _this.cropObj = { cropZoom: 0, defaultZoom: 0, totalPannedPoint: { x: 0, y: 0 }, totalPannedClientPoint: { x: 0, y: 0 },
181
- totalPannedInternalPoint: { x: 0, y: 0 }, activeObj: {}, rotateFlipColl: [], degree: 0,
182
- currFlipState: '', destPoints: { startX: 0, startY: 0, width: 0, height: 0 },
183
- srcPoints: { startX: 0, startY: 0, width: 0, height: 0 } };
181
+ totalPannedInternalPoint: { x: 0, y: 0 }, tempFlipPanPoint: { x: 0, y: 0 }, activeObj: {}, rotateFlipColl: [],
182
+ degree: 0, currFlipState: '', destPoints: { startX: 0, startY: 0, width: 0, height: 0 },
183
+ srcPoints: { startX: 0, startY: 0, width: 0, height: 0 }, filter: '' };
184
184
  _this.afterCropActions = [];
185
185
  _this.isCancelAction = false;
186
186
  _this.isFreehandPointMoved = false;
@@ -399,7 +399,6 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
399
399
  this.unwireEvent();
400
400
  _super.prototype.destroy.call(this);
401
401
  this.element.innerHTML = '';
402
- this.trigger('destroyed');
403
402
  };
404
403
  ImageEditor.prototype.initialize = function () {
405
404
  this.updateFinetunes();
@@ -967,7 +966,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
967
966
  redo.parentElement.classList.remove('e-overlay');
968
967
  }
969
968
  var zoomIn = document.querySelector('#' + this.element.id + '_zoomIn');
970
- if (!isNullOrUndefined(zoomIn) && this.zoomFactor >= 5) {
969
+ if (!isNullOrUndefined(zoomIn) && this.zoomFactor >= 2) {
971
970
  zoomIn.classList.add('e-disabled');
972
971
  zoomIn.parentElement.classList.add('e-overlay');
973
972
  }
@@ -1180,32 +1179,34 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1180
1179
  ImageEditor.prototype.cropSelect = function (args) {
1181
1180
  this.isCropTab = true;
1182
1181
  this.zoomFactor = this.cropZoomFactor;
1183
- var activeObj = this.activeObj;
1182
+ var prevCropObj = extend({}, this.cropObj, {}, true);
1183
+ var previousObj = this.getCurrentObj();
1184
+ previousObj.objColl = extend([], this.objColl, [], true);
1185
+ previousObj.pointColl = extend([], this.pointColl, [], true);
1186
+ previousObj.afterCropActions = this.afterCropActions;
1184
1187
  var text = args.item.id;
1185
1188
  this.currentToolbar = 'crop';
1186
1189
  this.currSelectionPoint = null;
1187
1190
  this.select(text);
1188
1191
  this.refreshToolbar('main', true, true);
1189
1192
  this.refreshDropDownBtn(true);
1190
- this.undoRedoColl.push({ operation: 'selectionTransform', value: null,
1191
- currentObj: extend([], this.objColl, [], true),
1192
- previousObj: extend([], this.objColl, [], true),
1193
- previousSelectionObj: extend({}, activeObj, {}, true),
1194
- currentSelectionObj: extend({}, this.activeObj, {}, true),
1195
- zoomFactor: this.zoomFactor, sharpen: this.adjustmentLevel.sharpen, bw: this.adjustmentLevel.bw });
1196
- this.undoRedoStep++;
1193
+ this.updateUndoRedoColl('selectionTransform', previousObj, previousObj.objColl, previousObj.pointColl, prevCropObj);
1197
1194
  this.enableDisableToolbarBtn();
1198
1195
  };
1199
1196
  ImageEditor.prototype.transformSelect = function (args) {
1200
1197
  this.cropSelectedState();
1201
1198
  this.currentSelectionPoint = null;
1202
1199
  this.performTransformation(args.item.id);
1203
- this.afterCropActions.push(args.item.id);
1204
1200
  };
1205
1201
  ImageEditor.prototype.performTransformation = function (text) {
1206
1202
  var tempZoomFactor = this.defaultZoomFactor;
1207
1203
  var isUndoRedo = this.isUndoRedo;
1204
+ var prevCropObj = extend({}, this.cropObj, {}, true);
1208
1205
  if (this.defaultZoomFactor !== 0) {
1206
+ this.transformCurrentObj = this.getCurrentObj();
1207
+ this.transformCurrentObj.objColl = extend([], this.objColl, null, true);
1208
+ this.transformCurrentObj.pointColl = extend({}, this.pointColl, null, true);
1209
+ this.transformCurrentObj.afterCropActions = extend([], this.afterCropActions, [], true);
1209
1210
  this.isUndoRedo = true;
1210
1211
  if (this.defaultZoomFactor > 0) {
1211
1212
  this.zoom(-this.defaultZoomFactor);
@@ -1220,10 +1221,19 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1220
1221
  this.isUndoRedo = true;
1221
1222
  this.zoom(tempZoomFactor);
1222
1223
  this.isUndoRedo = isUndoRedo;
1224
+ var state = '';
1225
+ if (text === 'rotateleft' || text === 'rotateright') {
1226
+ state = 'rotate';
1227
+ }
1228
+ else if (text === 'horizontalflip' || text === 'verticalflip') {
1229
+ state = 'flip';
1230
+ }
1231
+ this.updateUndoRedoColl(state, this.transformCurrentObj, this.transformCurrentObj.objColl, this.transformCurrentObj.pointColl, prevCropObj);
1232
+ this.transformCurrentObj = null;
1223
1233
  }
1224
1234
  };
1225
1235
  ImageEditor.prototype.updateTransform = function (text) {
1226
- switch (text) {
1236
+ switch (text.toLowerCase()) {
1227
1237
  case 'rotateleft':
1228
1238
  this.rotate(-90);
1229
1239
  break;
@@ -1325,15 +1335,16 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1325
1335
  showButtons: false, mode: 'Palette', cssClass: 'e-shape-fill-color',
1326
1336
  change: function (args) {
1327
1337
  _this.pushActItemIntoObj();
1328
- var objColl = extend([], _this.objColl, [], true);
1338
+ var prevCropObj = extend({}, _this.cropObj, {}, true);
1339
+ var prevObj = _this.getCurrentObj();
1340
+ prevObj.objColl = extend([], _this.objColl, [], true);
1341
+ prevObj.pointColl = extend([], _this.pointColl, [], true);
1342
+ prevObj.afterCropActions = extend([], _this.afterCropActions, [], true);
1329
1343
  _this.objColl.pop();
1330
1344
  proxy.activeObj.strokeSettings.fillColor = args.currentValue.hex;
1331
1345
  proxy.strokeSettings.fillColor = proxy.activeObj.strokeSettings.fillColor;
1332
1346
  _this.objColl.push(_this.activeObj);
1333
- proxy.undoRedoColl.push({ operation: 'shapeTransform', value: null, currentObj: extend([], proxy.objColl, [], true),
1334
- previousObj: objColl, zoomFactor: proxy.zoomFactor, sharpen: proxy.adjustmentLevel.sharpen,
1335
- bw: proxy.adjustmentLevel.bw });
1336
- proxy.undoRedoStep++;
1347
+ _this.updateUndoRedoColl('shapeTransform', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
1337
1348
  proxy.redrawShape(proxy.objColl[proxy.objColl.length - 1]);
1338
1349
  if (args.currentValue.rgba === '') {
1339
1350
  fillDDB_1.element.children[0].classList.add('e-nocolor-item');
@@ -1368,17 +1379,17 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1368
1379
  showButtons: false, mode: 'Palette', cssClass: 'e-shape-stroke-color',
1369
1380
  change: function (args) {
1370
1381
  _this.pushActItemIntoObj();
1371
- var objColl = extend([], _this.objColl, [], true);
1382
+ var prevCropObj = extend({}, _this.cropObj, {}, true);
1383
+ var prevObj = _this.getCurrentObj();
1384
+ prevObj.objColl = extend([], _this.objColl, [], true);
1385
+ prevObj.pointColl = extend([], _this.pointColl, [], true);
1386
+ prevObj.afterCropActions = extend([], _this.afterCropActions, [], true);
1372
1387
  _this.objColl.pop();
1373
1388
  proxy.activeObj.strokeSettings.strokeColor = args.currentValue.hex;
1374
1389
  proxy.strokeSettings.strokeColor = proxy.activeObj.strokeSettings.strokeColor;
1375
1390
  if (!proxy.togglePen) {
1376
1391
  _this.objColl.push(_this.activeObj);
1377
- proxy.undoRedoColl.push({ operation: 'shapeTransform', value: null,
1378
- currentObj: extend([], proxy.objColl, [], true),
1379
- previousObj: objColl, zoomFactor: proxy.zoomFactor,
1380
- sharpen: proxy.adjustmentLevel.sharpen, bw: proxy.adjustmentLevel.bw });
1381
- proxy.undoRedoStep++;
1392
+ proxy.updateUndoRedoColl('shapeTransform', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
1382
1393
  proxy.redrawShape(proxy.objColl[proxy.objColl.length - 1]);
1383
1394
  }
1384
1395
  strokeDDB_1.element.children[0].style.backgroundColor = args.currentValue.rgba;
@@ -1429,18 +1440,18 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1429
1440
  },
1430
1441
  select: function (args) {
1431
1442
  _this.pushActItemIntoObj();
1432
- var objColl = extend([], _this.objColl, [], true);
1443
+ var prevCropObj = extend({}, _this.cropObj, {}, true);
1444
+ var prevObj = _this.getCurrentObj();
1445
+ prevObj.objColl = extend([], _this.objColl, [], true);
1446
+ prevObj.pointColl = extend([], _this.pointColl, [], true);
1447
+ prevObj.afterCropActions = extend([], _this.afterCropActions, [], true);
1433
1448
  _this.objColl.pop();
1434
1449
  spanElem_1.textContent = args.item.text;
1435
1450
  _this.activeObj.strokeSettings.strokeWidth = parseInt(args.item.id, 10);
1436
1451
  _this.activeObj.strokeSettings.strokeWidth *= 2;
1437
1452
  _this.strokeSettings.strokeWidth = _this.activeObj.strokeSettings.strokeWidth;
1438
1453
  _this.objColl.push(_this.activeObj);
1439
- _this.undoRedoColl.push({ operation: 'shapeTransform', value: null,
1440
- currentObj: extend([], _this.objColl, [], true),
1441
- previousObj: objColl, zoomFactor: _this.zoomFactor,
1442
- sharpen: _this.adjustmentLevel.sharpen, bw: _this.adjustmentLevel.bw });
1443
- _this.undoRedoStep++;
1454
+ _this.updateUndoRedoColl('shapeTransform', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
1444
1455
  _this.redrawShape(_this.objColl[_this.objColl.length - 1]);
1445
1456
  if (Browser.isDevice) {
1446
1457
  if (!isNullOrUndefined(document.getElementById(_this.element.id + '_bottomToolbar'))) {
@@ -1571,17 +1582,17 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1571
1582
  showButtons: false, mode: 'Palette', cssClass: 'e-text-fontt-color',
1572
1583
  change: function (args) {
1573
1584
  _this.pushActItemIntoObj();
1574
- var objColl = extend([], _this.objColl, [], true);
1585
+ var prevCropObj = extend({}, _this.cropObj, {}, true);
1586
+ var prevObj = _this.getCurrentObj();
1587
+ prevObj.objColl = extend([], _this.objColl, [], true);
1588
+ prevObj.pointColl = extend([], _this.pointColl, [], true);
1589
+ prevObj.afterCropActions = extend([], _this.afterCropActions, [], true);
1575
1590
  _this.objColl.pop();
1576
1591
  if (proxy.textArea.style.display === 'none') {
1577
1592
  proxy.strokeSettings.strokeColor = proxy.activeObj.strokeSettings.strokeColor = args.currentValue.hex;
1578
1593
  if (!proxy.togglePen) {
1579
1594
  _this.objColl.push(_this.activeObj);
1580
- proxy.undoRedoColl.push({ operation: 'shapeTransform',
1581
- value: null, currentObj: extend([], proxy.objColl, [], true),
1582
- previousObj: objColl, zoomFactor: proxy.zoomFactor,
1583
- sharpen: proxy.adjustmentLevel.sharpen, bw: proxy.adjustmentLevel.bw });
1584
- proxy.undoRedoStep++;
1595
+ proxy.updateUndoRedoColl('shapeTransform', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
1585
1596
  proxy.redrawShape(proxy.objColl[proxy.objColl.length - 1]);
1586
1597
  }
1587
1598
  }
@@ -1590,21 +1601,13 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1590
1601
  var temp = proxy.activeObj.strokeSettings.strokeColor;
1591
1602
  proxy.activeObj.strokeSettings.strokeColor = args.currentValue.hex;
1592
1603
  _this.objColl.push(_this.activeObj);
1593
- _this.undoRedoColl.push({ operation: 'textTransform', value: null,
1594
- currentObj: extend([], _this.objColl, [], true),
1595
- previousObj: objColl, zoomFactor: proxy.zoomFactor,
1596
- sharpen: proxy.adjustmentLevel.sharpen, bw: proxy.adjustmentLevel.bw });
1597
- _this.undoRedoStep++;
1604
+ _this.updateUndoRedoColl('textAreaCustomization', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
1598
1605
  _this.objColl.pop();
1599
1606
  proxy.activeObj.strokeSettings.strokeColor = temp;
1600
1607
  }
1601
1608
  else if (!proxy.togglePen) {
1602
1609
  _this.objColl.push(_this.activeObj);
1603
- proxy.undoRedoColl.push({ operation: 'shapeTransform', value: null,
1604
- currentObj: extend([], proxy.objColl, [], true),
1605
- previousObj: objColl, zoomFactor: proxy.zoomFactor,
1606
- sharpen: proxy.adjustmentLevel.sharpen, bw: proxy.adjustmentLevel.bw });
1607
- proxy.undoRedoStep++;
1610
+ _this.updateUndoRedoColl('shapeTransform', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
1608
1611
  proxy.redrawShape(proxy.objColl[proxy.objColl.length - 1]);
1609
1612
  }
1610
1613
  strokeDDB_2.element.children[0].style.backgroundColor = args.currentValue.rgba;
@@ -1676,6 +1679,11 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1676
1679
  select: function (args) {
1677
1680
  _this.pushActItemIntoObj();
1678
1681
  var objColl = extend([], _this.objColl, [], true);
1682
+ var prevCropObj = extend({}, _this.cropObj, {}, true);
1683
+ var prevObj = _this.getCurrentObj();
1684
+ prevObj.objColl = extend([], _this.objColl, [], true);
1685
+ prevObj.pointColl = extend([], _this.pointColl, [], true);
1686
+ prevObj.afterCropActions = extend([], _this.afterCropActions, [], true);
1679
1687
  _this.objColl.pop();
1680
1688
  spanElem_2.textContent = args.item.text;
1681
1689
  if (Browser.isDevice) {
@@ -1687,11 +1695,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1687
1695
  _this.activeObj.textSettings.fontFamily = _this.toPascalCase(args.item.id);
1688
1696
  _this.redrawText();
1689
1697
  _this.objColl.push(_this.activeObj);
1690
- _this.undoRedoColl.push({ operation: 'textTransform', value: null,
1691
- currentObj: extend([], _this.objColl, [], true),
1692
- previousObj: objColl, zoomFactor: _this.zoomFactor,
1693
- sharpen: _this.adjustmentLevel.sharpen, bw: _this.adjustmentLevel.bw });
1694
- _this.undoRedoStep++;
1698
+ _this.updateUndoRedoColl('textAreaCustomization', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
1695
1699
  _this.objColl.pop();
1696
1700
  _this.upperContext.clearRect(0, 0, _this.upperCanvas.width, _this.upperCanvas.height);
1697
1701
  var width = _this.activeObj.activePoint.width +
@@ -1706,11 +1710,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1706
1710
  _this.textSettings.fontFamily = _this.activeObj.textSettings.fontFamily = _this.toPascalCase(args.item.id);
1707
1711
  _this.redrawText();
1708
1712
  _this.objColl.push(_this.activeObj);
1709
- _this.undoRedoColl.push({ operation: 'shapeTransform', value: null,
1710
- currentObj: extend([], _this.objColl, [], true),
1711
- previousObj: objColl, zoomFactor: _this.zoomFactor,
1712
- sharpen: _this.adjustmentLevel.sharpen, bw: _this.adjustmentLevel.bw });
1713
- _this.undoRedoStep++;
1713
+ _this.updateUndoRedoColl('shapeTransform', prevObj, objColl, extend([], _this.pointColl, [], true), prevCropObj);
1714
1714
  _this.redrawShape(_this.objColl[_this.objColl.length - 1]);
1715
1715
  }
1716
1716
  }
@@ -1811,7 +1811,11 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1811
1811
  },
1812
1812
  select: function (args) {
1813
1813
  _this.pushActItemIntoObj();
1814
- var objColl = extend([], _this.objColl, [], true);
1814
+ var prevCropObj = extend({}, _this.cropObj, {}, true);
1815
+ var prevObj = _this.getCurrentObj();
1816
+ prevObj.objColl = extend([], _this.objColl, [], true);
1817
+ prevObj.pointColl = extend([], _this.pointColl, [], true);
1818
+ prevObj.afterCropActions = extend([], _this.afterCropActions, [], true);
1815
1819
  _this.objColl.pop();
1816
1820
  fontSizeSpanElem_1.textContent = args.item.text;
1817
1821
  if (_this.textArea.style.display === 'block') {
@@ -1819,11 +1823,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1819
1823
  var temp = _this.activeObj.textSettings.fontSize;
1820
1824
  _this.activeObj.textSettings.fontSize = parseInt(_this.fontSizeColl[(parseInt(args.item.text, 10) - 1)].text, 10);
1821
1825
  _this.objColl.push(_this.activeObj);
1822
- _this.undoRedoColl.push({ operation: 'textTransform', value: null,
1823
- currentObj: extend([], _this.objColl, [], true),
1824
- previousObj: objColl, zoomFactor: _this.zoomFactor,
1825
- sharpen: _this.adjustmentLevel.sharpen, bw: _this.adjustmentLevel.bw });
1826
- _this.undoRedoStep++;
1826
+ _this.updateUndoRedoColl('textAreaCustomization', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
1827
1827
  _this.objColl.pop();
1828
1828
  var textStyle = '';
1829
1829
  if (_this.textArea.style.fontWeight === 'bold') {
@@ -1863,11 +1863,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1863
1863
  _this.updateActiveObject(_this.activeObj.activePoint, _this.activeObj);
1864
1864
  _this.redrawText();
1865
1865
  _this.objColl.push(_this.activeObj);
1866
- _this.undoRedoColl.push({ operation: 'shapeTransform', value: null,
1867
- currentObj: extend([], _this.objColl, [], true),
1868
- previousObj: objColl, zoomFactor: _this.zoomFactor,
1869
- sharpen: _this.adjustmentLevel.sharpen, bw: _this.adjustmentLevel.bw });
1870
- _this.undoRedoStep++;
1866
+ _this.updateUndoRedoColl('shapeTransform', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
1871
1867
  _this.redrawShape(_this.objColl[_this.objColl.length - 1]);
1872
1868
  }
1873
1869
  }
@@ -1927,14 +1923,27 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1927
1923
  return width;
1928
1924
  };
1929
1925
  ImageEditor.prototype.updateUndoRedoObj = function (objColl) {
1930
- this.objColl.push(this.activeObj);
1931
- this.undoRedoColl.push({ operation: 'shapeTransform', value: null,
1932
- currentObj: extend([], this.objColl, [], true), previousObj: objColl, zoomFactor: this.zoomFactor,
1933
- sharpen: this.adjustmentLevel.sharpen, bw: this.adjustmentLevel.bw });
1934
- this.undoRedoStep++;
1935
- this.redrawShape(this.objColl[this.objColl.length - 1]);
1926
+ if (this.allowUndoRedo) {
1927
+ this.objColl.push(this.activeObj);
1928
+ var cropObj = extend({}, this.cropObj, {}, true);
1929
+ var obj = this.getCurrentObj();
1930
+ obj.objColl = extend([], this.objColl, [], true);
1931
+ obj.pointColl = extend([], this.pointColl, [], true);
1932
+ obj.afterCropActions = extend([], this.afterCropActions, [], true);
1933
+ this.undoRedoColl.push({ operation: 'shapeTransform', previousObj: obj, currentObj: obj,
1934
+ previousObjColl: objColl, currentObjColl: obj.objColl,
1935
+ previousPointColl: obj.pointColl, currentPointColl: obj.pointColl,
1936
+ previousCropObj: cropObj, currentCropObj: cropObj });
1937
+ this.undoRedoStep++;
1938
+ this.redrawShape(this.objColl[this.objColl.length - 1]);
1939
+ }
1936
1940
  };
1937
1941
  ImageEditor.prototype.updateObjColl = function (item, objColl) {
1942
+ var prevCropObj = extend({}, this.cropObj, {}, true);
1943
+ var prevObj = this.getCurrentObj();
1944
+ prevObj.objColl = extend([], this.objColl, [], true);
1945
+ prevObj.pointColl = extend([], this.pointColl, [], true);
1946
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
1938
1947
  var tempBold = this.activeObj.textSettings.bold;
1939
1948
  var tempItalic = this.activeObj.textSettings.italic;
1940
1949
  switch (item) {
@@ -1956,10 +1965,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1956
1965
  break;
1957
1966
  }
1958
1967
  this.objColl.push(this.activeObj);
1959
- this.undoRedoColl.push({ operation: 'textTransform', value: null,
1960
- currentObj: extend([], this.objColl, [], true), previousObj: objColl, zoomFactor: this.zoomFactor,
1961
- sharpen: this.adjustmentLevel.sharpen, bw: this.adjustmentLevel.bw });
1962
- this.undoRedoStep++;
1968
+ this.updateUndoRedoColl('textAreaCustomization', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
1963
1969
  this.objColl.pop();
1964
1970
  this.activeObj.textSettings.bold = tempBold;
1965
1971
  this.activeObj.textSettings.italic = tempItalic;
@@ -2188,7 +2194,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
2188
2194
  this.disablePan = false;
2189
2195
  }
2190
2196
  zoomIn = document.querySelector('#' + this.element.id + '_zoomIn');
2191
- if (!isNullOrUndefined(zoomIn) && this.zoomFactor >= 5) {
2197
+ if (!isNullOrUndefined(zoomIn) && this.zoomFactor >= 2) {
2192
2198
  zoomIn.classList.add('e-disabled');
2193
2199
  zoomIn.parentElement.classList.add('e-overlay');
2194
2200
  }
@@ -2208,7 +2214,12 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
2208
2214
  break;
2209
2215
  case 'crop':
2210
2216
  if (!isNullOrUndefined(this.currSelectionPoint)) {
2211
- this.select('Custom');
2217
+ if (this.currObjType.isUndoAction) {
2218
+ this.refreshUndoRedoColl();
2219
+ }
2220
+ if (!isNullOrUndefined(this.cropObj.activeObj.shape)) {
2221
+ this.select(this.cropObj.activeObj.shape);
2222
+ }
2212
2223
  this.refreshToolbar('main', true, true);
2213
2224
  getComponent(this.element.querySelector('#' + this.element.id + '_cropBtn'), 'dropdown-btn').toggle();
2214
2225
  if (!isNullOrUndefined(this.activeObj.shape)) {
@@ -2220,12 +2231,12 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
2220
2231
  imageEditorObj.reset();
2221
2232
  this.currentToolbar = 'main';
2222
2233
  break;
2223
- case 'undo':
2224
- this.callUndo();
2225
- break;
2226
- case 'redo':
2227
- this.callRedo();
2228
- break;
2234
+ // case 'undo':
2235
+ // this.callUndo();
2236
+ // break;
2237
+ // case 'redo':
2238
+ // this.callRedo();
2239
+ // break;
2229
2240
  case 'adjustment':
2230
2241
  if (!isDisabledAdjustment) {
2231
2242
  this.refreshToolbar('adjustment');
@@ -2257,6 +2268,9 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
2257
2268
  case 'sepia':
2258
2269
  case 'invert':
2259
2270
  case 'sharpen':
2271
+ if (this.currObjType.isUndoAction) {
2272
+ this.refreshUndoRedoColl();
2273
+ }
2260
2274
  this.currObjType.isFiltered = true;
2261
2275
  this.setFilter(type);
2262
2276
  break;
@@ -2289,7 +2303,6 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
2289
2303
  this.currObjType.isFiltered = false;
2290
2304
  this.adjustmentLevel = extend({}, this.tempAdjustmentLevel, {}, true);
2291
2305
  this.element.querySelector('.e-contextual-toolbar-wrapper').classList.add('e-hide');
2292
- this.undoRedoColl = extend([], this.tempUndoRedoColl, [], true);
2293
2306
  this.undoRedoStep = this.tempUndoRedoStep;
2294
2307
  this.upperCanvas.style.cursor = 'default';
2295
2308
  this.currObjType.isCustomCrop = false;
@@ -2328,7 +2341,9 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
2328
2341
  this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
2329
2342
  this.renderImage();
2330
2343
  this.refreshToolbar('main');
2331
- this.pointColl[this.freehandDrawSelectedIndex].isSelected = false;
2344
+ if (!isNullOrUndefined(this.pointColl[this.freehandDrawSelectedIndex])) {
2345
+ this.pointColl[this.freehandDrawSelectedIndex].isSelected = false;
2346
+ }
2332
2347
  this.isFreehandDrawEditing = this.isFreehandDrawingPoint = false;
2333
2348
  this.freehandDrawHoveredIndex = this.freehandDrawSelectedIndex = null;
2334
2349
  };
@@ -2340,8 +2355,10 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
2340
2355
  this.pointColl[n].strokeWidth = this.tempFreeHandDrawEditingStyles.strokeWidth;
2341
2356
  }
2342
2357
  this.pointCounter = 0;
2343
- this.pointColl[this.freehandDrawSelectedIndex].isSelected = false;
2344
- this.freehandDrawHoveredIndex = this.freehandDrawSelectedIndex = null;
2358
+ if (!isNullOrUndefined(this.pointColl[this.freehandDrawSelectedIndex])) {
2359
+ this.pointColl[this.freehandDrawSelectedIndex].isSelected = false;
2360
+ }
2361
+ this.freehandDrawHoveredIndex = this.freehandDrawSelectedIndex = this.freehandDrawSelectedId = null;
2345
2362
  this.isFreehandDrawEditing = this.isFreehandDrawingPoint = false;
2346
2363
  this.tempFreeHandDrawEditingStyles = { strokeColor: null, strokeWidth: null, fillColor: null };
2347
2364
  this.refreshToolbar('main');
@@ -2877,6 +2894,9 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
2877
2894
  width: Browser.isDevice ? '200px' : '300px',
2878
2895
  cssClass: 'e-slider',
2879
2896
  change: function (args) {
2897
+ if (_this.currObjType.isUndoAction) {
2898
+ _this.refreshUndoRedoColl();
2899
+ }
2880
2900
  _this.setCurrAdjustmentValue(type, args.value);
2881
2901
  _this.enableDisableToolbarBtn();
2882
2902
  }
@@ -2981,11 +3001,80 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
2981
3001
  this.iterateObjColl();
2982
3002
  this.freehandRedraw(this.lowerContext);
2983
3003
  this.lowerContext.filter = temp;
3004
+ this.currSelectionPoint = null;
3005
+ }
3006
+ else {
3007
+ if (this.cropObj.cropZoom > 0) {
3008
+ var cropObjColl_1 = extend([], this.objColl, null, true);
3009
+ var cropPointColl_1 = extend([], this.pointColl, null, true);
3010
+ this.objColl = [];
3011
+ this.pointColl = [];
3012
+ this.freehandCounter = 0;
3013
+ this.zoom(this.cropObj.cropZoom);
3014
+ this.objColl = cropObjColl_1;
3015
+ this.pointColl = cropPointColl_1;
3016
+ this.freehandCounter = this.pointColl.length;
3017
+ this.currSelectionPoint = extend({}, this.cropObj.activeObj, null, true);
3018
+ if (this.cropObj.currFlipState !== '') {
3019
+ this.cropObj.totalPannedPoint.x += this.cropObj.tempFlipPanPoint.x;
3020
+ this.cropObj.totalPannedPoint.y += this.cropObj.tempFlipPanPoint.y;
3021
+ }
3022
+ }
3023
+ var destPoints = { startX: this.destLeft, startY: this.destTop, width: this.destWidth, height: this.destHeight };
3024
+ this.destLeft = this.currSelectionPoint.activePoint.startX;
3025
+ this.destTop = this.currSelectionPoint.activePoint.startY;
3026
+ this.destWidth = this.currSelectionPoint.activePoint.width;
3027
+ this.destHeight = this.currSelectionPoint.activePoint.height;
3028
+ this.zoomObjColl();
3029
+ this.zoomFreehandDrawColl();
3030
+ this.destLeft = destPoints.startX;
3031
+ this.destTop = destPoints.startY;
3032
+ this.destWidth = destPoints.width;
3033
+ this.destHeight = destPoints.height;
3034
+ this.updatePannedRegion();
3035
+ this.updateObjAndFreeHandDrawColl();
3036
+ var cropObjColl = extend([], this.objColl, null, true);
3037
+ var cropPointColl = extend([], this.pointColl, null, true);
3038
+ this.objColl = [];
3039
+ this.pointColl = [];
3040
+ this.freehandCounter = 0;
3041
+ this.setCurrentObj();
3042
+ var activeObj = extend({}, this.activeObj, null, true);
3043
+ this.refreshActiveObj();
3044
+ this.objColl = cropObjColl;
3045
+ this.pointColl = cropPointColl;
3046
+ this.freehandCounter = this.pointColl.length;
3047
+ this.zoomObjColl();
3048
+ this.zoomFreehandDrawColl();
3049
+ this.currSelectionPoint = null;
3050
+ if (this.degree === 0) {
3051
+ this.drawPannImage({ x: 0, y: 0 });
3052
+ }
3053
+ this.activeObj = activeObj;
3054
+ this.drawObject('duplicate');
3055
+ }
3056
+ };
3057
+ ImageEditor.prototype.updatePannedRegion = function () {
3058
+ var pannedPoint = this.degree === 0 ? this.cropObj.totalPannedPoint : this.cropObj.totalPannedClientPoint;
3059
+ if (this.currFlipState === this.cropObj.currFlipState) {
3060
+ this.panObjColl(-pannedPoint.x, -pannedPoint.y, '');
3061
+ this.panFreehandDrawColl(-pannedPoint.x, -pannedPoint.y, '');
2984
3062
  }
2985
3063
  else {
2986
- this.setCropObj();
3064
+ if (this.currFlipState === 'horizontal' && this.cropObj.currFlipState === '' ||
3065
+ this.currFlipState === 'vertical' && this.cropObj.currFlipState === '') {
3066
+ this.panObjColl(-pannedPoint.x, -pannedPoint.y, '');
3067
+ this.panFreehandDrawColl(-pannedPoint.x, -pannedPoint.y, '');
3068
+ }
3069
+ else if (this.currFlipState === '' && this.cropObj.currFlipState === 'horizontal') {
3070
+ this.panObjColl(pannedPoint.x, -pannedPoint.y, '');
3071
+ this.panFreehandDrawColl(pannedPoint.x, -pannedPoint.y, '');
3072
+ }
3073
+ else if (this.currFlipState === '' && this.cropObj.currFlipState === 'vertical') {
3074
+ this.panObjColl(-pannedPoint.x, pannedPoint.y, '');
3075
+ this.panFreehandDrawColl(-pannedPoint.x, pannedPoint.y, '');
3076
+ }
2987
3077
  }
2988
- this.currSelectionPoint = null;
2989
3078
  };
2990
3079
  ImageEditor.prototype.updateObjAndFreeHandDrawColl = function () {
2991
3080
  for (var i = 0; i < this.objColl.length; i++) {
@@ -3105,7 +3194,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
3105
3194
  var activeObj = extend({}, this.activeObj, {});
3106
3195
  this.destLeft += (-this.totalPannedPoint.x);
3107
3196
  this.destTop += (-this.totalPannedPoint.y);
3108
- this.drawPannImage({ x: -this.totalPannedPoint.x, y: -this.totalPannedPoint.y }, this.getCurrentPanRegion());
3197
+ this.drawPannImage({ x: -this.totalPannedPoint.x, y: -this.totalPannedPoint.y });
3109
3198
  this.updateFlipPan(activeObj);
3110
3199
  this.totalPannedPoint = { x: 0, y: 0 };
3111
3200
  }
@@ -3125,6 +3214,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
3125
3214
  else {
3126
3215
  this.zoom(Math.abs(length_1));
3127
3216
  }
3217
+ this.cropZoomFactor = this.tempZoomFactor;
3128
3218
  }
3129
3219
  else {
3130
3220
  this.isCancelAction = true;
@@ -3134,7 +3224,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
3134
3224
  this.freehandCounter = 0;
3135
3225
  var cropObj = extend({}, this.cropObj, {});
3136
3226
  var afterCropActions = extend([], this.afterCropActions, {}, true);
3137
- this.setCropObj();
3227
+ this.setCurrentObj();
3138
3228
  this.cropImg();
3139
3229
  this.cropObj = cropObj;
3140
3230
  this.afterCropActions = afterCropActions;
@@ -3187,6 +3277,11 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
3187
3277
  }
3188
3278
  }
3189
3279
  context.closePath();
3280
+ var prevCropObj = extend({}, this.cropObj, {}, true);
3281
+ var prevObj = this.getCurrentObj();
3282
+ prevObj.objColl = extend([], this.objColl, [], true);
3283
+ prevObj.pointColl = extend([], this.pointColl, [], true);
3284
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
3190
3285
  this.pointColl[this.freehandCounter] = {};
3191
3286
  this.pointColl[this.freehandCounter].points = extend([], this.points);
3192
3287
  this.pointColl[this.freehandCounter].strokeColor = this.activeObj.strokeSettings.strokeColor;
@@ -3198,16 +3293,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
3198
3293
  this.freehandCounter++;
3199
3294
  this.currentFreehandDrawIndex++;
3200
3295
  this.isFreehandDrawing = false;
3201
- /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
3202
- var currentObj = extend([], this.pointColl, [], true);
3203
- this.pointColl = {};
3204
- for (var i = 0; i < this.freehandCounter - 1; i++) {
3205
- this.pointColl[i] = currentObj[i];
3206
- }
3207
- /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
3208
- var previousObj = extend([], this.pointColl, [], true);
3209
- this.updateUndoRedoColl('freehanddraw', null, previousObj, currentObj, this.zoomFactor);
3210
- this.pointColl = currentObj;
3296
+ this.updateUndoRedoColl('freehanddraw', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
3211
3297
  };
3212
3298
  ImageEditor.prototype.freehandMoveHandler = function (e) {
3213
3299
  this.isFreehandPointMoved = true;
@@ -3691,8 +3777,11 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
3691
3777
  /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
3692
3778
  var temp = extend([], _this.pointColl, [], true);
3693
3779
  _this.updateFreehandDrawColorChange();
3694
- /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
3695
- var previousObj = extend([], _this.pointColl, [], true);
3780
+ var prevCropObj = extend({}, _this.cropObj, {}, true);
3781
+ var prevObj = _this.getCurrentObj();
3782
+ prevObj.objColl = extend([], _this.objColl, [], true);
3783
+ prevObj.pointColl = extend([], _this.pointColl, [], true);
3784
+ prevObj.afterCropActions = extend([], _this.afterCropActions, [], true);
3696
3785
  _this.pointColl = temp;
3697
3786
  proxy.isFreehandDrawCustomized = true;
3698
3787
  proxy.activeObj.strokeSettings.strokeColor = proxy.selectedFreehandColor = args.currentValue.hex;
@@ -3700,7 +3789,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
3700
3789
  _this.upperContext.clearRect(0, 0, _this.upperCanvas.width, _this.upperCanvas.height);
3701
3790
  _this.pointColl[_this.freehandDrawSelectedIndex].strokeColor = args.currentValue.hex;
3702
3791
  _this.hoverFreehandraw(args.currentValue.hex);
3703
- _this.updateUndoRedoColl('freehanddrawCustomized', null, previousObj, _this.pointColl, _this.zoomFactor);
3792
+ _this.updateUndoRedoColl('freehanddrawCustomized', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
3704
3793
  }
3705
3794
  else if (!proxy.togglePen) {
3706
3795
  proxy.redrawShape(_this.activeObj);
@@ -3765,8 +3854,11 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
3765
3854
  /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
3766
3855
  var temp = extend([], _this.pointColl, [], true);
3767
3856
  _this.updateFreehandDrawColorChange();
3768
- /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
3769
- var previousObj = extend([], _this.pointColl, [], true);
3857
+ var prevCropObj = extend({}, _this.cropObj, {}, true);
3858
+ var prevObj = _this.getCurrentObj();
3859
+ prevObj.objColl = extend([], _this.objColl, [], true);
3860
+ prevObj.pointColl = extend([], _this.pointColl, [], true);
3861
+ prevObj.afterCropActions = extend([], _this.afterCropActions, [], true);
3770
3862
  _this.pointColl = temp;
3771
3863
  _this.isFreehandDrawCustomized = true;
3772
3864
  spanElem_3.textContent = args.item.text;
@@ -3775,7 +3867,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
3775
3867
  _this.upperContext.clearRect(0, 0, _this.upperCanvas.width, _this.upperCanvas.height);
3776
3868
  _this.hoverFreehandraw(null, _this.penStrokeWidth);
3777
3869
  _this.pointColl[_this.freehandDrawSelectedIndex].strokeWidth = _this.penStrokeWidth;
3778
- _this.updateUndoRedoColl('freehanddrawCustomized', null, previousObj, _this.pointColl, _this.zoomFactor);
3870
+ _this.updateUndoRedoColl('freehanddrawCustomized', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
3779
3871
  }
3780
3872
  if (Browser.isDevice) {
3781
3873
  if (!isNullOrUndefined(document.getElementById(_this.element.id + '_bottomToolbar'))) {
@@ -3984,6 +4076,9 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
3984
4076
  this.destLeft += this.totalPannedInternalPoint.x;
3985
4077
  this.destTop += this.totalPannedInternalPoint.y;
3986
4078
  var temp = this.lowerContext.filter;
4079
+ if (this.degree === 0) {
4080
+ this.setDestPointsForFlipState();
4081
+ }
3987
4082
  this.updateBrightnessFilter();
3988
4083
  this.lowerContext.drawImage(this.baseImg, this.srcLeft, this.srcTop, this.srcWidth, this.srcHeight, this.destLeft, this.destTop, this.destWidth, this.destHeight);
3989
4084
  this.updateCurrentTransformedState('reverse');
@@ -4227,6 +4322,10 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
4227
4322
  context.strokeStyle = '#fff';
4228
4323
  minStrokeWidth = maxStrokeWidth = this.penStrokeWidth = strokeWidth ?
4229
4324
  strokeWidth : this.pointColl[idx].strokeWidth;
4325
+ if (len === 1) {
4326
+ controlPoint1 = controlPoint2 = startPoint = endPoint = this.points[0];
4327
+ this.startDraw(context, controlPoint1, controlPoint2, startPoint, endPoint, minStrokeWidth, maxStrokeWidth);
4328
+ }
4230
4329
  for (var l = 0; l < len - 3; l++) {
4231
4330
  if (this.points[l + 1] && this.points[l + 2] && this.points[l + 2]) {
4232
4331
  controlPoint1 = (this.calcCurveControlPoints(this.points[l + 0], this.points[l + 1], this.points[l + 2])).controlPoint2;
@@ -4235,55 +4334,64 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
4235
4334
  endPoint = this.points[l + 2];
4236
4335
  this.startDraw(context, controlPoint1, controlPoint2, startPoint, endPoint, minStrokeWidth, maxStrokeWidth);
4237
4336
  }
4238
- if (len === 1) {
4239
- controlPoint1 = controlPoint2 = startPoint = endPoint = this.points[0];
4240
- this.startDraw(context, controlPoint1, controlPoint2, startPoint, endPoint, minStrokeWidth, maxStrokeWidth);
4241
- }
4242
4337
  }
4243
4338
  context.closePath();
4244
4339
  };
4245
- ImageEditor.prototype.flipFreehandrawColl = function (value) {
4246
- if (value.toLowerCase() === 'horizontal') {
4247
- for (var n = 0; n < this.freehandCounter; n++) {
4248
- if (this.pointColl[n].shapeFlip !== this.currFlipState) {
4249
- this.points = extend([], this.pointColl[n].points, []);
4250
- this.pointCounter = 0;
4251
- var len = this.points.length;
4252
- for (var l = 0; l < len; l++) {
4253
- if (this.points[l].x <= this.destLeft + (this.destWidth / 2)) {
4254
- this.points[l].x = (this.destLeft + this.destWidth) - (this.points[l].x - this.destLeft);
4255
- }
4256
- else if (this.points[l].x >= this.destLeft + (this.destWidth / 2)) {
4257
- this.points[l].x = this.destLeft + (this.destLeft + this.destWidth - this.points[l].x);
4258
- }
4259
- this.points[l].ratioX = (this.points[l].x - this.destLeft) / this.destWidth;
4260
- this.points[l].ratioY = (this.points[l].y - this.destTop) / this.destHeight;
4340
+ ImageEditor.prototype.pointsHorizontalFlip = function () {
4341
+ for (var n = 0; n < this.freehandCounter; n++) {
4342
+ if (this.pointColl[n].shapeFlip !== this.currFlipState) {
4343
+ this.points = extend([], this.pointColl[n].points, []);
4344
+ this.pointCounter = 0;
4345
+ var len = this.points.length;
4346
+ for (var l = 0; l < len; l++) {
4347
+ if (this.points[l].x <= this.destLeft + (this.destWidth / 2)) {
4348
+ this.points[l].x = (this.destLeft + this.destWidth) - (this.points[l].x - this.destLeft);
4261
4349
  }
4262
- this.pointColl[n].shapeFlip = this.currFlipState;
4350
+ else if (this.points[l].x >= this.destLeft + (this.destWidth / 2)) {
4351
+ this.points[l].x = this.destLeft + (this.destLeft + this.destWidth - this.points[l].x);
4352
+ }
4353
+ this.points[l].ratioX = (this.points[l].x - this.destLeft) / this.destWidth;
4354
+ this.points[l].ratioY = (this.points[l].y - this.destTop) / this.destHeight;
4263
4355
  }
4356
+ this.pointColl[n].shapeFlip = this.currFlipState;
4264
4357
  }
4265
4358
  }
4266
- else {
4267
- for (var n = 0; n < this.freehandCounter; n++) {
4268
- if (this.pointColl[n].shapeFlip !== this.currFlipState) {
4269
- this.points = extend([], this.pointColl[n].points, []);
4270
- this.pointCounter = 0;
4271
- var len = this.points.length;
4272
- for (var l = 0; l < len; l++) {
4273
- if (this.points[l].y <= this.destTop + (this.destHeight / 2)) {
4274
- this.points[l].y = (this.destTop + this.destHeight) - (this.points[l].y - this.destTop);
4275
- }
4276
- else if (this.points[l].y >= this.destTop + (this.destHeight / 2)) {
4277
- this.points[l].y = this.destTop + (this.destTop + this.destHeight - this.points[l].y);
4278
- }
4279
- this.points[l].ratioX = (this.points[l].x - this.destLeft) / this.destWidth;
4280
- this.points[l].ratioY = (this.points[l].y - this.destTop) / this.destHeight;
4359
+ };
4360
+ ImageEditor.prototype.pointsVerticalFlip = function () {
4361
+ for (var n = 0; n < this.freehandCounter; n++) {
4362
+ if (this.pointColl[n].shapeFlip !== this.currFlipState) {
4363
+ this.points = extend([], this.pointColl[n].points, []);
4364
+ this.pointCounter = 0;
4365
+ var len = this.points.length;
4366
+ for (var l = 0; l < len; l++) {
4367
+ if (this.points[l].y <= this.destTop + (this.destHeight / 2)) {
4368
+ this.points[l].y = (this.destTop + this.destHeight) - (this.points[l].y - this.destTop);
4369
+ }
4370
+ else if (this.points[l].y >= this.destTop + (this.destHeight / 2)) {
4371
+ this.points[l].y = this.destTop + (this.destTop + this.destHeight - this.points[l].y);
4281
4372
  }
4282
- this.pointColl[n].shapeFlip = this.currFlipState;
4373
+ this.points[l].ratioX = (this.points[l].x - this.destLeft) / this.destWidth;
4374
+ this.points[l].ratioY = (this.points[l].y - this.destTop) / this.destHeight;
4283
4375
  }
4376
+ this.pointColl[n].shapeFlip = this.currFlipState;
4284
4377
  }
4285
4378
  }
4286
4379
  };
4380
+ ImageEditor.prototype.flipFreehandrawColl = function (value) {
4381
+ if (value.toLowerCase() === 'horizontal') {
4382
+ this.pointsHorizontalFlip();
4383
+ }
4384
+ else if (value.toLowerCase() === 'vertical') {
4385
+ this.pointsVerticalFlip();
4386
+ }
4387
+ else {
4388
+ this.pointsHorizontalFlip();
4389
+ for (var i = 0; i < this.freehandCounter; i++) {
4390
+ this.pointColl[i].shapeFlip = '';
4391
+ }
4392
+ this.pointsVerticalFlip();
4393
+ }
4394
+ };
4287
4395
  ImageEditor.prototype.rotateFreehandDrawColl = function () {
4288
4396
  for (var n = 0; n < this.freehandCounter; n++) {
4289
4397
  this.points = extend([], this.pointColl[n].points, []);
@@ -4305,7 +4413,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
4305
4413
  }
4306
4414
  }
4307
4415
  };
4308
- ImageEditor.prototype.zoomFreehandDrawColl = function () {
4416
+ ImageEditor.prototype.zoomFreehandDrawColl = function (isPreventApply) {
4309
4417
  for (var n = 0; n < this.freehandCounter; n++) {
4310
4418
  this.points = extend([], this.pointColl[n].points, []);
4311
4419
  this.pointCounter = 0;
@@ -4315,7 +4423,9 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
4315
4423
  this.points[l].y = this.zoomY(this.points[l].ratioY);
4316
4424
  }
4317
4425
  }
4318
- this.freehandRedraw(this.lowerContext);
4426
+ if (isNullOrUndefined(isPreventApply)) {
4427
+ this.freehandRedraw(this.lowerContext);
4428
+ }
4319
4429
  };
4320
4430
  ImageEditor.prototype.zoomX = function (x) {
4321
4431
  return (x * this.destWidth) + this.destLeft;
@@ -4484,170 +4594,154 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
4484
4594
  };
4485
4595
  ImageEditor.prototype.updateCropObj = function () {
4486
4596
  this.afterCropActions = [];
4487
- this.cropObj.cropZoom = this.cropZoomFactor;
4488
- this.cropObj.defaultZoom = this.defaultZoomFactor;
4489
- this.cropObj.totalPannedPoint = extend({}, this.totalPannedPoint, {}, true);
4490
- this.cropObj.totalPannedClientPoint = extend({}, this.totalPannedClientPoint, {}, true);
4491
- this.cropObj.totalPannedInternalPoint = extend({}, this.totalPannedInternalPoint, {}, true);
4492
- this.cropObj.activeObj = extend({}, this.activeObj, {}, true);
4493
- this.cropObj.rotateFlipColl = extend([], this.rotateFlipColl, [], true);
4494
- this.cropObj.degree = this.degree;
4495
- this.cropObj.currFlipState = this.currFlipState;
4496
- this.cropObj.destPoints = { startX: this.destLeft, startY: this.destTop, endX: 0, endY: 0,
4497
- width: this.destWidth, height: this.destHeight };
4498
- this.cropObj.srcPoints = { startX: this.srcLeft, startY: this.srcTop, endX: 0, endY: 0,
4499
- width: this.srcWidth, height: this.srcHeight };
4597
+ var obj = this.getCurrentObj();
4598
+ this.cropObj = extend({}, obj, {}, true);
4500
4599
  };
4501
- ImageEditor.prototype.setCropObj = function () {
4502
- this.cropZoomFactor = this.zoomFactor = this.cropObj.cropZoom;
4503
- this.defaultZoomFactor = this.cropObj.defaultZoom;
4504
- this.totalPannedPoint = extend({}, this.cropObj.totalPannedPoint, {}, true);
4505
- this.totalPannedClientPoint = extend({}, this.cropObj.totalPannedClientPoint, {}, true);
4506
- this.totalPannedInternalPoint = extend({}, this.cropObj.totalPannedInternalPoint, {}, true);
4507
- this.rotateFlipColl = extend([], this.cropObj.rotateFlipColl, [], true);
4508
- this.degree = this.cropObj.degree;
4509
- this.currFlipState = this.cropObj.currFlipState;
4510
- this.destLeft = this.cropObj.destPoints.startX;
4511
- this.destTop = this.cropObj.destPoints.startY;
4512
- this.destWidth = this.cropObj.destPoints.width;
4513
- this.destHeight = this.cropObj.destPoints.height;
4514
- this.srcLeft = this.cropObj.srcPoints.startX;
4515
- this.srcTop = this.cropObj.srcPoints.startY;
4516
- this.srcWidth = this.cropObj.srcPoints.width;
4517
- this.srcHeight = this.cropObj.srcPoints.height;
4518
- this.drawCropSelectionImage();
4519
- if (this.degree !== 0) {
4520
- this.isCircleCrop = false;
4521
- if (!isNullOrUndefined(this.currSelectionPoint)) {
4522
- this.currSelectionPoint.shape = '';
4600
+ ImageEditor.prototype.setCurrentObj = function (obj) {
4601
+ var isObj = obj ? true : false;
4602
+ obj = obj ? obj : this.cropObj;
4603
+ this.cropZoomFactor = obj.cropZoom;
4604
+ this.defaultZoomFactor = obj.defaultZoom;
4605
+ if (!isObj) {
4606
+ this.zoomFactor = obj.cropZoom;
4607
+ }
4608
+ else {
4609
+ if (!isNullOrUndefined(obj.activeObj.shape) && obj.activeObj.shape.split('-')[0] === 'crop') {
4610
+ this.zoomFactor = obj.cropZoom;
4611
+ }
4612
+ else {
4613
+ this.zoomFactor = obj.defaultZoom;
4614
+ }
4615
+ }
4616
+ this.totalPannedPoint = extend({}, obj.totalPannedPoint, {}, true);
4617
+ this.totalPannedClientPoint = extend({}, obj.totalPannedClientPoint, {}, true);
4618
+ this.totalPannedInternalPoint = extend({}, obj.totalPannedInternalPoint, {}, true);
4619
+ this.tempFlipPanPoint = extend({}, obj.tempFlipPanPoint, {}, true);
4620
+ this.rotateFlipColl = extend([], obj.rotateFlipColl, [], true);
4621
+ this.degree = obj.degree;
4622
+ this.currFlipState = obj.currFlipState;
4623
+ this.destLeft = obj.destPoints.startX;
4624
+ this.destTop = obj.destPoints.startY;
4625
+ this.destWidth = obj.destPoints.width;
4626
+ this.destHeight = obj.destPoints.height;
4627
+ this.srcLeft = obj.srcPoints.startX;
4628
+ this.srcTop = obj.srcPoints.startY;
4629
+ this.srcWidth = obj.srcPoints.width;
4630
+ this.srcHeight = obj.srcPoints.height;
4631
+ this.lowerContext.filter = obj.filter;
4632
+ if (this.lowerContext.filter.split(' ').length > 1) {
4633
+ if (this.lowerContext.filter.split(' ')[0].split('(')[1].split(')')[0] === '1') {
4634
+ this.isBrightnessAdjusted = false;
4635
+ }
4636
+ else {
4637
+ this.isBrightnessAdjusted = true;
4523
4638
  }
4639
+ }
4640
+ var isCircleCrop = this.isCircleCrop;
4641
+ var currSelectionPoint = extend({}, this.currSelectionPoint, {}, true);
4642
+ this.currSelectionPoint = null;
4643
+ this.isCircleCrop = false;
4644
+ this.drawCropSelectionImage(obj, false);
4645
+ if (this.degree !== 0) {
4524
4646
  this.currentPannedPoint = { x: 0, y: 0 };
4525
4647
  this.rotatePan();
4526
4648
  }
4527
- this.activeObj = extend({}, this.cropObj.activeObj, {}, true);
4649
+ this.activeObj = extend({}, obj.activeObj, {}, true);
4528
4650
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
4529
- this.drawObject('duplicate');
4530
- var activeObj = extend({}, this.cropObj.activeObj, {}, true);
4651
+ if (this.activeObj.activePoint.width !== 0 && this.activeObj.activePoint.height !== 0) {
4652
+ this.drawObject('duplicate');
4653
+ }
4654
+ var activeObj = extend({}, obj.activeObj, {}, true);
4531
4655
  var isAfterCropAction = false;
4532
- if (this.afterCropActions.length > 0) {
4656
+ this.afterCropActions = this.alignRotateFlipColl(this.afterCropActions);
4657
+ var afterCropActions = extend([], this.afterCropActions, [], true);
4658
+ if (!isObj && afterCropActions.length > 0) {
4533
4659
  isAfterCropAction = true;
4534
- var objColl = extend([], this.objColl, {}, true);
4535
- var pointColl = extend([], this.pointColl, {}, true);
4536
- var freehandCounter = this.freehandCounter;
4537
- this.objColl = [];
4538
- this.pointColl = [];
4539
- this.freehandCounter = 0;
4540
- var isCircleCrop = this.isCircleCrop;
4541
- var currSelectionPoint = extend({}, this.currSelectionPoint, {}, true);
4542
- this.currSelectionPoint = null;
4543
- this.isCircleCrop = false;
4544
- var isFlip = false;
4545
- for (var i = 0; i < this.afterCropActions.length; i++) {
4660
+ for (var i = 0; i < afterCropActions.length; i++) {
4546
4661
  if (this.degree % 90 === 0 && this.degree % 180 !== 0 &&
4547
- (this.afterCropActions[i] === 'horizontalflip' || this.afterCropActions[i] === 'verticalflip')) {
4662
+ (afterCropActions[i] === 'horizontalflip' || afterCropActions[i] === 'verticalflip')) {
4548
4663
  this.rotatedFlipCropSelection = true;
4549
4664
  }
4550
- this.updateTransform(this.afterCropActions[i]);
4551
- if (this.afterCropActions[i] === 'horizontalflip' || this.afterCropActions[i] === 'verticalflip') {
4552
- if (this.degree === 0) {
4553
- this.destLeft += this.totalPannedPoint.x;
4554
- this.destTop += this.totalPannedPoint.y;
4665
+ this.updateTransform(afterCropActions[i]);
4666
+ if (afterCropActions[i] === 'horizontalflip' || afterCropActions[i] === 'verticalflip') {
4667
+ if (afterCropActions.length === 1) {
4668
+ this.activeObj = extend({}, this.cropObj.activeObj, {}, true);
4669
+ this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
4670
+ this.drawObject('duplicate');
4555
4671
  }
4556
- isFlip = true;
4557
4672
  }
4558
4673
  }
4559
- this.isCircleCrop = isCircleCrop;
4560
- this.currSelectionPoint = currSelectionPoint;
4561
- var destPoints = { startX: this.destLeft, startY: this.destTop, width: this.destWidth, height: this.destHeight };
4562
4674
  activeObj = extend({}, this.activeObj, {}, true);
4563
- this.refreshActiveObj();
4564
- this.objColl = objColl;
4565
- this.pointColl = pointColl;
4566
- this.freehandCounter = freehandCounter;
4567
- if (this.rotateFlipColl.length > 1 && typeof (this.rotateFlipColl[this.rotateFlipColl.length - 1]) === 'string') {
4568
- this.iterateObjColl();
4569
- this.freehandRedraw(this.lowerContext);
4570
- }
4571
- else if (this.rotateFlipColl.length > 1 && typeof (this.rotateFlipColl[this.rotateFlipColl.length - 1]) === 'number' ||
4572
- this.rotateFlipColl.length >= 0) {
4573
- this.destLeft = activeObj.activePoint.startX;
4574
- this.destTop = activeObj.activePoint.startY;
4575
- this.destWidth = activeObj.activePoint.width;
4576
- this.destHeight = activeObj.activePoint.height;
4577
- this.zoomObjColl();
4578
- this.zoomFreehandDrawColl();
4579
- }
4580
- this.destLeft = destPoints.startX;
4581
- this.destTop = destPoints.startY;
4582
- this.destWidth = destPoints.width;
4583
- this.destHeight = destPoints.height;
4584
4675
  this.totalPannedPoint = { x: 0, y: 0 };
4585
4676
  this.totalPannedClientPoint = { x: 0, y: 0 };
4586
4677
  this.totalPannedInternalPoint = { x: 0, y: 0 };
4587
4678
  this.activeObj = activeObj;
4588
4679
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
4589
- this.drawObject('duplicate');
4590
- if (this.cropObj.degree !== this.degree) {
4680
+ if (this.activeObj.activePoint.width !== 0 && this.activeObj.activePoint.height !== 0) {
4681
+ this.drawObject('duplicate');
4682
+ }
4683
+ if (obj.degree !== this.degree) {
4591
4684
  this.cropZoomFactor = this.zoomFactor = 0;
4592
4685
  }
4593
4686
  this.updateObjAndFreeHandDrawColl();
4594
- if (isFlip) {
4595
- if (this.degree === 0) {
4596
- var currSelectionPoint_1 = extend({}, this.currSelectionPoint, {}, true);
4597
- this.currSelectionPoint = null;
4598
- this.isCircleCrop = false;
4599
- this.drawPannImage({ x: 0, y: 0 }, this.getCurrentPanRegion());
4600
- this.updateFlipPan(activeObj);
4601
- this.isCircleCrop = isCircleCrop;
4602
- this.currSelectionPoint = currSelectionPoint_1;
4603
- }
4604
- this.activeObj = activeObj;
4605
- this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
4606
- this.drawObject('duplicate');
4607
- }
4608
4687
  if (this.rotatedFlipCropSelection) {
4609
4688
  // this.totalPannedInternalPoint = extend({}, this.cropObj.totalPannedInternalPoint, {}, true) as Point;
4610
4689
  this.rotatedFlipCropSelection = false;
4611
4690
  }
4612
4691
  }
4692
+ this.afterCropActions = afterCropActions;
4613
4693
  if (!this.isCancelAction && !isAfterCropAction) {
4614
- this.setDestPointsForFlipState();
4615
4694
  this.updateObjAndFreeHandDrawColl();
4616
4695
  this.zoomFreehandDrawColl();
4617
- this.destLeft = this.cropObj.destPoints.startX;
4618
- this.destTop = this.cropObj.destPoints.startY;
4696
+ this.destLeft = obj.destPoints.startX;
4697
+ this.destTop = obj.destPoints.startY;
4619
4698
  }
4620
4699
  this.activeObj = activeObj;
4700
+ this.isCircleCrop = isCircleCrop;
4701
+ this.currSelectionPoint = currSelectionPoint;
4621
4702
  };
4622
- ImageEditor.prototype.drawCropSelectionImage = function () {
4703
+ ImageEditor.prototype.drawCropSelectionImage = function (obj, isObj) {
4623
4704
  var temp = this.lowerContext.filter;
4624
4705
  this.upperContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
4625
4706
  this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
4626
4707
  this.reverseTransformedState();
4627
- this.iterateRotateFlipColl(this.lowerContext, 'initial');
4708
+ if (isObj) {
4709
+ this.updateCurrentTransformedState('initial');
4710
+ }
4711
+ else {
4712
+ this.iterateRotateFlipColl(this.lowerContext, 'initial');
4713
+ }
4714
+ this.setDestPointsForFlipState();
4628
4715
  this.updateBrightnessFilter();
4629
4716
  this.lowerContext.drawImage(this.baseImg, this.srcLeft, this.srcTop, this.srcWidth, this.srcHeight, this.destLeft, this.destTop, this.destWidth, this.destHeight);
4630
- this.iterateRotateFlipColl(this.lowerContext, 'reverse');
4631
- var activeObj = extend({}, this.cropObj.activeObj, {}, true);
4717
+ if (isObj) {
4718
+ this.updateCurrentTransformedState('reverse');
4719
+ }
4720
+ else {
4721
+ this.iterateRotateFlipColl(this.lowerContext, 'reverse');
4722
+ }
4723
+ this.destLeft = this.cropObj.destPoints.startX;
4724
+ this.destTop = this.cropObj.destPoints.startY;
4725
+ var activeObj = extend({}, obj.activeObj, {}, true);
4632
4726
  this.lowerContext.filter = 'none';
4633
4727
  if (this.isCancelAction) {
4634
4728
  this.zoomObjColl();
4635
4729
  this.zoomFreehandDrawColl();
4636
4730
  }
4637
4731
  else {
4638
- this.destLeft = this.cropObj.destPoints.startX;
4639
- this.destTop = this.cropObj.destPoints.startY;
4640
- this.destWidth = this.cropObj.destPoints.width;
4641
- this.destHeight = this.cropObj.destPoints.height;
4642
- this.srcLeft = this.cropObj.srcPoints.startX;
4643
- this.srcTop = this.cropObj.srcPoints.startY;
4644
- this.srcWidth = this.cropObj.srcPoints.width;
4645
- this.srcHeight = this.cropObj.srcPoints.height;
4732
+ this.destLeft = obj.destPoints.startX;
4733
+ this.destTop = obj.destPoints.startY;
4734
+ this.destWidth = obj.destPoints.width;
4735
+ this.destHeight = obj.destPoints.height;
4736
+ this.srcLeft = obj.srcPoints.startX;
4737
+ this.srcTop = obj.srcPoints.startY;
4738
+ this.srcWidth = obj.srcPoints.width;
4739
+ this.srcHeight = obj.srcPoints.height;
4646
4740
  var destPoints = { startX: this.destLeft, startY: this.destTop, width: this.destWidth, height: this.destHeight };
4647
- this.destLeft = this.cropObj.activeObj.activePoint.startX;
4648
- this.destTop = this.cropObj.activeObj.activePoint.startY;
4649
- this.destWidth = this.cropObj.activeObj.activePoint.width;
4650
- this.destHeight = this.cropObj.activeObj.activePoint.height;
4741
+ this.destLeft = obj.activeObj.activePoint.startX;
4742
+ this.destTop = obj.activeObj.activePoint.startY;
4743
+ this.destWidth = obj.activeObj.activePoint.width;
4744
+ this.destHeight = obj.activeObj.activePoint.height;
4651
4745
  this.zoomObjColl();
4652
4746
  this.zoomFreehandDrawColl();
4653
4747
  this.destLeft = destPoints.startX;
@@ -4664,10 +4758,12 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
4664
4758
  }
4665
4759
  if (isNullOrUndefined(isRotateCrop) && this.degree !== 0) {
4666
4760
  this.updateCropObj();
4761
+ this.currDestinationPoint = { startX: this.destLeft, startY: this.destTop, width: this.destWidth, height: this.destHeight };
4667
4762
  this.rotateCrop();
4668
4763
  }
4669
4764
  else if (isNullOrUndefined(isRotateCrop) && this.currFlipState !== '') {
4670
4765
  this.updateCropObj();
4766
+ this.currDestinationPoint = { startX: this.destLeft, startY: this.destTop, width: this.destWidth, height: this.destHeight };
4671
4767
  this.flipCrop();
4672
4768
  }
4673
4769
  else {
@@ -4677,6 +4773,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
4677
4773
  this.updateCropObj();
4678
4774
  this.resetPanPoints();
4679
4775
  this.updateImageRatioForActObj();
4776
+ this.currDestinationPoint = { startX: this.destLeft, startY: this.destTop, width: this.destWidth, height: this.destHeight };
4680
4777
  this.currSelectionPoint = extend({}, this.activeObj, {}, true);
4681
4778
  this.cropDestPoints = { startX: this.destLeft, startY: this.destTop, width: this.destWidth, height: this.destHeight };
4682
4779
  }
@@ -4866,21 +4963,35 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
4866
4963
  }
4867
4964
  return panRegion;
4868
4965
  };
4869
- ImageEditor.prototype.drawPannImage = function (point, panRegion) {
4966
+ ImageEditor.prototype.drawPannImage = function (point) {
4967
+ var destPoints = { startX: this.destLeft, startY: this.destTop, width: this.destWidth, height: this.destHeight };
4870
4968
  this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
4969
+ this.updateCurrentTransformedState('initial');
4970
+ this.destLeft = destPoints.startX;
4971
+ this.destTop = destPoints.startY;
4972
+ this.destWidth = destPoints.width;
4973
+ this.destHeight = destPoints.height;
4974
+ this.setDestPointsForFlipState();
4871
4975
  this.updateBrightnessFilter();
4872
4976
  this.lowerContext.drawImage(this.baseImg, this.srcLeft, this.srcTop, this.srcWidth, this.srcHeight, this.destLeft, this.destTop, this.destWidth, this.destHeight);
4873
4977
  if ((!isNullOrUndefined(this.currSelectionPoint) && this.currSelectionPoint.shape === 'crop-circle') || this.isCircleCrop) {
4874
4978
  this.cropCircle(this.lowerContext, null, true);
4875
4979
  }
4980
+ this.updateCurrentTransformedState('reverse');
4981
+ this.destLeft = destPoints.startX;
4982
+ this.destTop = destPoints.startY;
4983
+ this.destWidth = destPoints.width;
4984
+ this.destHeight = destPoints.height;
4876
4985
  this.lowerContext.filter = 'none';
4877
- this.panObjColl(point.x, point.y, panRegion);
4878
- this.panFreehandDrawColl(point.x, point.y, panRegion);
4986
+ this.panObjColl(point.x, point.y, '');
4987
+ this.panFreehandDrawColl(point.x, point.y, '');
4879
4988
  if (this.isCircleCrop) {
4880
4989
  this.cropCircle(this.lowerContext, null, true);
4881
4990
  }
4882
4991
  };
4883
4992
  ImageEditor.prototype.drawPannedImage = function (xDiff, yDiff) {
4993
+ var panEventArgs = { startPoint: this.panDown, endPoint: this.panMove };
4994
+ this.trigger('panning', panEventArgs);
4884
4995
  var isObjCreated = false;
4885
4996
  if (isNullOrUndefined(this.activeObj.shape)) {
4886
4997
  isObjCreated = true;
@@ -4905,11 +5016,10 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
4905
5016
  this.updateActiveObject(this.activeObj.activePoint, this.activeObj);
4906
5017
  this.isCropTab = true;
4907
5018
  }
4908
- var panRegion = this.getCurrentPanRegion();
4909
5019
  if (this.degree === 0) {
4910
5020
  var point = void 0;
4911
5021
  if (isNullOrUndefined(xDiff) && isNullOrUndefined(yDiff)) {
4912
- point = this.updatePanPoints(panRegion);
5022
+ point = this.updatePanPoints('');
4913
5023
  }
4914
5024
  else {
4915
5025
  point = { x: xDiff, y: yDiff };
@@ -4918,7 +5028,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
4918
5028
  this.totalPannedPoint.y += point.y;
4919
5029
  var tempSelectionObj = extend({}, this.activeObj, {}, true);
4920
5030
  var temp = this.lowerContext.filter;
4921
- this.drawPannImage(point, panRegion);
5031
+ this.drawPannImage(point);
4922
5032
  this.lowerContext.filter = temp;
4923
5033
  this.tempPanMove = extend({}, this.panMove, {}, true);
4924
5034
  this.activeObj = extend({}, tempSelectionObj, {}, true);
@@ -4926,13 +5036,12 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
4926
5036
  if (!isNullOrUndefined(this.activeObj.shape)) {
4927
5037
  this.drawObject('duplicate', this.activeObj);
4928
5038
  }
4929
- this.updateFlipPan(tempSelectionObj);
4930
5039
  }
4931
5040
  else {
4932
5041
  var tempFlipState = this.currFlipState;
4933
5042
  this.isCropTab = true;
4934
5043
  if (isNullOrUndefined(xDiff) && isNullOrUndefined(yDiff)) {
4935
- this.currentPannedPoint = this.updatePanPoints(panRegion);
5044
+ this.currentPannedPoint = this.updatePanPoints('');
4936
5045
  }
4937
5046
  else {
4938
5047
  this.currentPannedPoint = { x: xDiff, y: yDiff };
@@ -5016,45 +5125,23 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
5016
5125
  var tempFlipColl = this.flipColl;
5017
5126
  this.flipColl = [];
5018
5127
  this.updateImageRatioForActObj();
5019
- this.currSelectionPoint = extend({}, this.activeObj, {}, true);
5128
+ this.objColl.push(this.activeObj);
5129
+ if (this.zoomFactor > 0) {
5130
+ var zoomFactor = this.zoomFactor;
5131
+ var isUndoRedo = this.isUndoRedo;
5132
+ for (var i = 0; i < (zoomFactor * 10); i++) {
5133
+ this.isUndoRedo = true;
5134
+ this.zoom(-0.1);
5135
+ }
5136
+ this.isUndoRedo = isUndoRedo;
5137
+ this.resetPanPoints();
5138
+ }
5139
+ this.currSelectionPoint = extend({}, this.objColl[this.objColl.length - 1], {}, true);
5020
5140
  this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
5021
5141
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
5022
5142
  var temp = this.lowerContext.filter;
5023
5143
  this.updateBrightnessFilter();
5024
- if (!isNullOrUndefined(this.tempPannedPoint) && this.totalPannedPoint.x === 0 && this.totalPannedPoint.y === 0) {
5025
- this.totalPannedPoint = extend({}, this.tempPannedPoint, {}, true);
5026
- this.tempPannedPoint = { x: 0, y: 0 };
5027
- }
5028
- var isPrevent = true;
5029
- if (!isNullOrUndefined(this.activeObj.shape) && this.activeObj.shape.split('-')[0] === 'crop' &&
5030
- this.zoomFactor === 0 && this.cropObj.cropZoom !== 0) {
5031
- isPrevent = false;
5032
- }
5033
- if (this.zoomFactor === 0 && isPrevent) {
5034
- if (this.totalPannedPoint.x > 0) {
5035
- this.destLeft -= Math.abs(this.totalPannedPoint.x);
5036
- }
5037
- else {
5038
- this.destLeft += Math.abs(this.totalPannedPoint.x);
5039
- }
5040
- if (this.totalPannedPoint.y > 0) {
5041
- this.destTop -= Math.abs(this.totalPannedPoint.y);
5042
- }
5043
- else {
5044
- this.destTop += Math.abs(this.totalPannedPoint.y);
5045
- }
5046
- }
5047
5144
  this.lowerContext.drawImage(this.baseImg, this.srcLeft, this.srcTop, this.srcWidth, this.srcHeight, this.destLeft, this.destTop, this.destWidth, this.destHeight);
5048
- var destLeft = this.destLeft;
5049
- var destTop = this.destTop;
5050
- if (this.currFlipState === 'horizontal' && this.zoomFactor > 0 && this.totalPannedPoint.x !== 0) {
5051
- this.destLeft = destLeft - this.totalPannedPoint.x;
5052
- }
5053
- else if (this.currFlipState === 'vertical' && this.zoomFactor > 0 && this.totalPannedPoint.y !== 0) {
5054
- this.destTop = destTop - this.totalPannedPoint.y;
5055
- }
5056
- this.updateImageRatioForActObj();
5057
- this.objColl.push(this.activeObj);
5058
5145
  for (var i = 0; i < this.objColl.length; i++) {
5059
5146
  this.objColl[i].shapeFlip = '';
5060
5147
  }
@@ -5062,37 +5149,21 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
5062
5149
  this.pointColl[i].shapeFlip = '';
5063
5150
  }
5064
5151
  this.redrawObj(this.getCurrentPanRegion());
5065
- this.flipFreehandrawColl(this.currFlipState);
5066
- if (this.zoomFactor === 0 && isPrevent) {
5067
- if (this.getCurrentPanRegion() === 'horizontal') {
5068
- this.panObjColl(this.totalPannedPoint.x, -this.totalPannedPoint.y, this.getCurrentPanRegion());
5069
- this.panFreehandDrawColl(this.totalPannedPoint.x, -this.totalPannedPoint.y, this.getCurrentPanRegion());
5070
- }
5071
- else if (this.getCurrentPanRegion() === 'vertical') {
5072
- this.panObjColl(-this.totalPannedPoint.x, this.totalPannedPoint.y, this.getCurrentPanRegion());
5073
- this.panFreehandDrawColl(-this.totalPannedPoint.x, this.totalPannedPoint.y, this.getCurrentPanRegion());
5074
- }
5075
- else {
5076
- this.panObjColl(-this.totalPannedPoint.x, -this.totalPannedPoint.y, this.getCurrentPanRegion());
5077
- this.panFreehandDrawColl(-this.totalPannedPoint.x, -this.totalPannedPoint.y, this.getCurrentPanRegion());
5078
- }
5079
- }
5152
+ this.flipFreehandrawColl(this.getCurrentPanRegion());
5080
5153
  this.activeObj = extend({}, this.objColl[this.objColl.length - 1], {}, true);
5081
5154
  this.objColl.pop();
5155
+ this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
5082
5156
  this.drawObject('duplicate');
5083
- this.destLeft = destLeft;
5084
- this.destTop = destTop;
5085
5157
  this.cropImg(true);
5086
- this.updateCurrentTransformedState('initial');
5158
+ this.isReverseRotate = true;
5159
+ this.reverseTransformedState();
5087
5160
  this.setDestinationPoints();
5161
+ this.currentTransformedState('initial');
5088
5162
  this.updateBrightnessFilter();
5089
5163
  this.lowerContext.drawImage(this.baseImg, this.srcLeft, this.srcTop, this.srcWidth, this.srcHeight, this.destLeft, this.destTop, this.destWidth, this.destHeight);
5090
5164
  this.lowerContext.filter = temp;
5091
5165
  this.isRotateZoom = false;
5092
5166
  this.updateCurrentTransformedState('reverse');
5093
- if (tempCurrFlipState === '' && this.currFlipState !== '') {
5094
- tempCurrFlipState = this.currFlipState;
5095
- }
5096
5167
  this.currFlipState = tempCurrFlipState;
5097
5168
  this.flipColl = tempFlipColl;
5098
5169
  this.lowerContext.filter = 'none';
@@ -5103,9 +5174,9 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
5103
5174
  this.pointColl[i].shapeFlip = '';
5104
5175
  }
5105
5176
  this.redrawObj(this.getCurrentPanRegion());
5106
- this.flipFreehandrawColl(this.currFlipState);
5107
- this.iterateObjColl();
5108
- this.freehandRedraw(this.lowerContext);
5177
+ this.flipFreehandrawColl(this.getCurrentPanRegion());
5178
+ this.zoomObjColl();
5179
+ this.zoomFreehandDrawColl();
5109
5180
  this.lowerContext.filter = temp;
5110
5181
  if ((!isNullOrUndefined(this.currSelectionPoint) && this.currSelectionPoint.shape === 'crop-circle') || this.isCircleCrop) {
5111
5182
  this.cropCircle(this.lowerContext);
@@ -5116,6 +5187,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
5116
5187
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
5117
5188
  this.isReverseFlip = false;
5118
5189
  this.resetPanPoints();
5190
+ this.tempFlipPanPoint = { x: 0, y: 0 };
5119
5191
  };
5120
5192
  ImageEditor.prototype.rotateCrop = function () {
5121
5193
  var shape = '';
@@ -5158,31 +5230,19 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
5158
5230
  }
5159
5231
  var activeObj = extend({}, this.objColl[this.objColl.length - 1], {}, true);
5160
5232
  if (this.currFlipState !== '') {
5161
- var flipState = '';
5162
5233
  for (var i = 0; i < this.objColl.length; i++) {
5163
5234
  this.objColl[i].shapeFlip = '';
5164
5235
  }
5165
- if (this.currFlipState === 'horizontal') {
5166
- flipState = this.degree % 90 === 0 && this.degree % 180 !== 0 ? 'vertical' : 'horizontal';
5167
- this.redrawObj(flipState);
5168
- }
5169
- else if (this.currFlipState === 'vertical') {
5170
- flipState = this.degree % 90 === 0 && this.degree % 180 !== 0 ? 'horizontal' : 'vertical';
5171
- this.redrawObj(flipState);
5172
- }
5173
5236
  for (var i = 0; i < this.freehandCounter; i++) {
5174
5237
  this.pointColl[i].shapeFlip = '';
5175
5238
  }
5176
- if (this.currFlipState === 'horizontal') {
5177
- flipState = this.degree % 90 === 0 && this.degree % 180 !== 0 ? 'vertical' : 'horizontal';
5178
- this.flipFreehandrawColl(flipState);
5179
- }
5180
- else if (this.currFlipState === 'vertical') {
5181
- flipState = this.degree % 90 === 0 && this.degree % 180 !== 0 ? 'horizontal' : 'vertical';
5182
- this.flipFreehandrawColl(flipState);
5183
- }
5239
+ var flipState = this.getCurrentCropState('initial');
5240
+ this.redrawObj(flipState);
5241
+ this.flipFreehandrawColl(flipState);
5184
5242
  }
5243
+ this.zoomObjColl();
5185
5244
  this.zoomFreehandDrawColl();
5245
+ activeObj = extend({}, this.objColl[this.objColl.length - 1], {}, true);
5186
5246
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
5187
5247
  this.drawObject('duplicate', activeObj);
5188
5248
  this.objColl.pop();
@@ -5211,25 +5271,16 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
5211
5271
  this.rotateObjColl();
5212
5272
  this.rotateFreehandDrawColl();
5213
5273
  }
5214
- if (this.currFlipState !== '') {
5274
+ if (this.getCurrentPanRegion() !== '') {
5215
5275
  for (var i = 0; i < this.objColl.length; i++) {
5216
5276
  this.objColl[i].shapeFlip = '';
5217
5277
  }
5218
- if (this.currFlipState === 'horizontal') {
5219
- this.redrawObj('horizontal');
5220
- }
5221
- else if (this.currFlipState === 'vertical') {
5222
- this.redrawObj('vertical');
5223
- }
5224
5278
  for (var i = 0; i < this.freehandCounter; i++) {
5225
5279
  this.pointColl[i].shapeFlip = '';
5226
5280
  }
5227
- if (this.currFlipState === 'horizontal') {
5228
- this.flipFreehandrawColl('horizontal');
5229
- }
5230
- else if (this.currFlipState === 'vertical') {
5231
- this.flipFreehandrawColl('vertical');
5232
- }
5281
+ var flipState = this.getCurrentCropState('reverse');
5282
+ this.redrawObj(flipState);
5283
+ this.flipFreehandrawColl(flipState);
5233
5284
  }
5234
5285
  this.isReverseRotate = false;
5235
5286
  if (shape === 'crop-circle') {
@@ -5252,37 +5303,141 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
5252
5303
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
5253
5304
  this.resetPanPoints();
5254
5305
  };
5255
- ImageEditor.prototype.updateRotatePanPoints = function () {
5256
- if (this.degree % 90 === 0 && this.degree % 180 !== 0) {
5257
- if (this.degree === 90 || this.degree === -270) {
5258
- this.destLeft += this.currentPannedPoint.y;
5259
- this.destTop -= this.currentPannedPoint.x;
5306
+ ImageEditor.prototype.getCurrentCropState = function (type, isAllowInvert) {
5307
+ var flipState = '';
5308
+ var state = [];
5309
+ if (type === 'initial') {
5310
+ if (this.degree === 180 || this.degree === -180) {
5311
+ flipState = this.flipColl.length > 1 ? this.getCurrentPanRegion() : this.currFlipState;
5260
5312
  }
5261
- else if (this.degree === 270 || this.degree === -90) {
5262
- this.destLeft -= this.currentPannedPoint.y;
5263
- this.destTop += this.currentPannedPoint.x;
5313
+ else {
5314
+ for (var i = 0; i < this.rotateFlipColl.length; i++) {
5315
+ if (typeof (this.rotateFlipColl[i]) === 'number') {
5316
+ state.push('number');
5317
+ }
5318
+ else if (typeof (this.rotateFlipColl[i]) === 'string') {
5319
+ state.push('string');
5320
+ }
5321
+ }
5322
+ if (state.length > 1 && state[state.length - 1] === 'string' && state[state.length - 2] === 'number') {
5323
+ if (this.currFlipState === 'horizontal') {
5324
+ flipState = 'vertical';
5325
+ }
5326
+ else if (this.currFlipState === 'vertical') {
5327
+ flipState = 'horizontal';
5328
+ }
5329
+ }
5330
+ else if (state.length > 1 && state[state.length - 1] === 'number' && state[state.length - 2] === 'string') {
5331
+ flipState = this.flipColl.length > 1 ? this.getCurrentPanRegion() : this.currFlipState;
5332
+ }
5264
5333
  }
5265
5334
  }
5266
5335
  else {
5267
- if (this.degree === 180 || this.degree === -180) {
5268
- this.destLeft -= this.currentPannedPoint.x;
5269
- this.destTop -= this.currentPannedPoint.y;
5270
- }
5271
- else {
5272
- this.destLeft += this.currentPannedPoint.x;
5273
- this.destTop += this.currentPannedPoint.y;
5336
+ flipState = this.getCurrentPanRegion();
5337
+ if (isAllowInvert || !this.isInitialRotate()) {
5338
+ if (this.degree === -90 || this.degree === -270) {
5339
+ if (flipState === 'horizontal') {
5340
+ flipState = 'vertical';
5341
+ }
5342
+ else if (flipState === 'vertical') {
5343
+ flipState = 'horizontal';
5344
+ }
5345
+ }
5274
5346
  }
5275
5347
  }
5348
+ if (flipState === '') {
5349
+ flipState = this.flipColl.length > 1 ? this.getCurrentPanRegion() : this.currFlipState;
5350
+ }
5351
+ return flipState;
5276
5352
  };
5277
- ImageEditor.prototype.rotatePan = function (isCropSelection) {
5278
- this.isReverseRotate = true;
5279
- var tempDegree = this.degree;
5280
- var rotatePanActiveObj;
5281
- if (!isNullOrUndefined(this.activeObj.activePoint) && !isNullOrUndefined(this.activeObj.shape)) {
5282
- rotatePanActiveObj = extend({}, this.activeObj, {}, true);
5353
+ ImageEditor.prototype.isInitialRotate = function () {
5354
+ var isRotate = false;
5355
+ if (this.rotateFlipColl.length > 0 && typeof (this.rotateFlipColl[0]) === 'number') {
5356
+ isRotate = true;
5283
5357
  }
5284
- var tempObjColl = extend([], this.objColl, [], true);
5358
+ return isRotate;
5359
+ };
5360
+ ImageEditor.prototype.updateRotatePanPoints = function () {
5361
+ var panRegion = '';
5362
+ if (this.isInitialRotate() && this.degree < 0) {
5363
+ panRegion = this.getCurrentCropState('reverse', true);
5364
+ }
5365
+ else {
5366
+ panRegion = this.getCurrentPanRegion();
5367
+ }
5368
+ if (this.degree % 90 === 0 && this.degree % 180 !== 0) {
5369
+ if (this.degree === 90 || (this.degree === -90 && (panRegion === 'horizontal' || panRegion === 'vertical'))
5370
+ || (this.degree === -270 && (panRegion === '' || panRegion === 'verticalHorizontal' || panRegion === 'horizontalVertical'))) {
5371
+ if (panRegion === '') {
5372
+ this.destLeft += this.currentPannedPoint.y;
5373
+ this.destTop -= this.currentPannedPoint.x;
5374
+ }
5375
+ else if (panRegion === 'horizontal') {
5376
+ this.destLeft += this.currentPannedPoint.y;
5377
+ this.destTop += this.currentPannedPoint.x;
5378
+ }
5379
+ else if (panRegion === 'vertical') {
5380
+ this.destLeft -= this.currentPannedPoint.y;
5381
+ this.destTop -= this.currentPannedPoint.x;
5382
+ }
5383
+ else {
5384
+ this.destLeft -= this.currentPannedPoint.y;
5385
+ this.destTop += this.currentPannedPoint.x;
5386
+ }
5387
+ }
5388
+ else if (this.degree === 270 || (this.degree === -270 && (panRegion === 'horizontal' || panRegion === 'vertical'))
5389
+ || (this.degree === -90 && (panRegion === '' || panRegion === 'verticalHorizontal' || panRegion === 'horizontalVertical'))) {
5390
+ if (panRegion === '') {
5391
+ this.destLeft -= this.currentPannedPoint.y;
5392
+ this.destTop += this.currentPannedPoint.x;
5393
+ }
5394
+ else if (panRegion === 'horizontal') {
5395
+ this.destLeft -= this.currentPannedPoint.y;
5396
+ this.destTop -= this.currentPannedPoint.x;
5397
+ }
5398
+ else if (panRegion === 'vertical') {
5399
+ this.destLeft += this.currentPannedPoint.y;
5400
+ this.destTop += this.currentPannedPoint.x;
5401
+ }
5402
+ else {
5403
+ this.destLeft += this.currentPannedPoint.y;
5404
+ this.destTop -= this.currentPannedPoint.x;
5405
+ }
5406
+ }
5407
+ }
5408
+ else {
5409
+ if (this.degree === 180 || this.degree === -180) {
5410
+ if (panRegion === '') {
5411
+ this.destLeft -= this.currentPannedPoint.x;
5412
+ this.destTop -= this.currentPannedPoint.y;
5413
+ }
5414
+ else if (panRegion === 'horizontal') {
5415
+ this.destLeft += this.currentPannedPoint.x;
5416
+ this.destTop -= this.currentPannedPoint.y;
5417
+ }
5418
+ else if (panRegion === 'vertical') {
5419
+ this.destLeft -= this.currentPannedPoint.x;
5420
+ this.destTop += this.currentPannedPoint.y;
5421
+ }
5422
+ else {
5423
+ this.destLeft += this.currentPannedPoint.x;
5424
+ this.destTop += this.currentPannedPoint.y;
5425
+ }
5426
+ }
5427
+ }
5428
+ };
5429
+ ImageEditor.prototype.rotatePan = function (isCropSelection, isDefaultZoom) {
5430
+ this.isReverseRotate = true;
5431
+ var tempDegree = this.degree;
5432
+ var rotatePanActiveObj;
5433
+ if (!isNullOrUndefined(this.activeObj.activePoint) && !isNullOrUndefined(this.activeObj.shape)) {
5434
+ rotatePanActiveObj = extend({}, this.activeObj, {}, true);
5435
+ }
5436
+ var tempObjColl = extend([], this.objColl, [], true);
5437
+ var tempPointColl = extend([], this.pointColl, [], true);
5285
5438
  this.objColl = [];
5439
+ this.pointColl = [];
5440
+ this.freehandCounter = 0;
5286
5441
  this.refreshActiveObj();
5287
5442
  this.isRotateZoom = true;
5288
5443
  this.updateCurrentTransformedState('initial');
@@ -5311,15 +5466,25 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
5311
5466
  this.totalPannedClientPoint.x = this.destLeft - destLeft;
5312
5467
  this.totalPannedClientPoint.y = this.destTop - destTop;
5313
5468
  this.objColl = tempObjColl;
5469
+ this.pointColl = tempPointColl;
5470
+ this.freehandCounter = this.pointColl.length;
5314
5471
  this.degree = tempDegree;
5315
- this.objColl = extend([], tempObjColl, [], true);
5316
5472
  this.lowerContext.filter = 'none';
5317
- var panRegion = this.getCurrentPanRegion();
5318
5473
  if (isCropSelection) {
5319
- this.currentPannedPoint = extend({}, this.totalPannedClientPoint, {}, true);
5474
+ if (isDefaultZoom) {
5475
+ this.totalPannedClientPoint.x = -this.totalPannedClientPoint.x;
5476
+ this.totalPannedClientPoint.y = -this.totalPannedClientPoint.y;
5477
+ this.currentPannedPoint = extend({}, this.totalPannedClientPoint, {}, true);
5478
+ this.totalPannedClientPoint = { x: 0, y: 0 };
5479
+ this.destLeft += this.currentPannedPoint.x;
5480
+ this.destTop += this.currentPannedPoint.y;
5481
+ }
5482
+ else {
5483
+ this.currentPannedPoint = extend({}, this.totalPannedClientPoint, {}, true);
5484
+ }
5320
5485
  }
5321
- this.panObjColl(this.currentPannedPoint.x, this.currentPannedPoint.y, panRegion);
5322
- this.panFreehandDrawColl(this.currentPannedPoint.x, this.currentPannedPoint.y, panRegion);
5486
+ this.panObjColl(this.currentPannedPoint.x, this.currentPannedPoint.y, '');
5487
+ this.panFreehandDrawColl(this.currentPannedPoint.x, this.currentPannedPoint.y, '');
5323
5488
  this.lowerContext.filter = temp;
5324
5489
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
5325
5490
  this.activeObj = extend({}, rotatePanActiveObj, {}, true);
@@ -5367,7 +5532,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
5367
5532
  this.zoomFactor += value;
5368
5533
  }
5369
5534
  if (this.isCropTab) {
5370
- this.cropZoomFactor += value;
5535
+ this.cropZoomFactor = this.zoomFactor;
5371
5536
  }
5372
5537
  else {
5373
5538
  this.defaultZoomFactor = this.zoomFactor;
@@ -5409,18 +5574,32 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
5409
5574
  }
5410
5575
  this.destLeft = destLeft - ((maxDimension.width - this.destWidth) / 2);
5411
5576
  this.destTop = destTop - ((maxDimension.height - this.destHeight) / 2);
5577
+ destLeft = this.destLeft;
5578
+ destTop = this.destTop;
5412
5579
  if (!isNullOrUndefined(selectionObj)) {
5413
5580
  if (this.destLeft > selectionObj.activePoint.startX) {
5414
5581
  this.destLeft = selectionObj.activePoint.startX;
5582
+ if (this.degree === 0) {
5583
+ this.totalPannedPoint.x -= (destLeft - this.destLeft);
5584
+ }
5415
5585
  }
5416
5586
  if (this.destTop > selectionObj.activePoint.startY) {
5417
5587
  this.destTop = selectionObj.activePoint.startY;
5588
+ if (this.degree === 0) {
5589
+ this.totalPannedPoint.y -= (destTop - this.destTop);
5590
+ }
5418
5591
  }
5419
5592
  if (this.destLeft + maxDimension.width < selectionObj.activePoint.endX) {
5420
5593
  this.destLeft = selectionObj.activePoint.endX - maxDimension.width;
5594
+ if (this.degree === 0) {
5595
+ this.totalPannedPoint.x -= (destLeft - this.destLeft);
5596
+ }
5421
5597
  }
5422
5598
  if (this.destTop + maxDimension.height < selectionObj.activePoint.endY) {
5423
5599
  this.destTop = selectionObj.activePoint.endY - maxDimension.height;
5600
+ if (this.degree === 0) {
5601
+ this.totalPannedPoint.y -= (destTop - this.destTop);
5602
+ }
5424
5603
  }
5425
5604
  }
5426
5605
  return maxDimension;
@@ -5642,11 +5821,44 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
5642
5821
  this.degree = 0;
5643
5822
  }
5644
5823
  };
5645
- ImageEditor.prototype.updateUndoRedoColl = function (operation, value, previousObj, currentObj, zoomFactor, sharpen, bw) {
5646
- if (!this.isInitialLoading) {
5824
+ ImageEditor.prototype.getCurrentObj = function () {
5825
+ var obj = { cropZoom: 0, defaultZoom: 0, totalPannedPoint: { x: 0, y: 0 }, totalPannedClientPoint: { x: 0, y: 0 },
5826
+ totalPannedInternalPoint: { x: 0, y: 0 }, tempFlipPanPoint: { x: 0, y: 0 }, activeObj: {},
5827
+ rotateFlipColl: [], degree: 0, currFlipState: '',
5828
+ destPoints: { startX: 0, startY: 0, width: 0, height: 0 },
5829
+ srcPoints: { startX: 0, startY: 0, width: 0, height: 0 }, filter: '' };
5830
+ obj.cropZoom = this.cropZoomFactor;
5831
+ obj.defaultZoom = this.defaultZoomFactor;
5832
+ obj.totalPannedPoint = extend({}, this.totalPannedPoint, {}, true);
5833
+ obj.totalPannedClientPoint = extend({}, this.totalPannedClientPoint, {}, true);
5834
+ obj.totalPannedInternalPoint = extend({}, this.totalPannedInternalPoint, {}, true);
5835
+ obj.tempFlipPanPoint = extend({}, this.tempFlipPanPoint, {}, true);
5836
+ obj.activeObj = extend({}, this.activeObj, {}, true);
5837
+ obj.rotateFlipColl = extend([], this.rotateFlipColl, [], true);
5838
+ obj.degree = this.degree;
5839
+ obj.currFlipState = this.currFlipState;
5840
+ obj.destPoints = { startX: this.destLeft, startY: this.destTop, endX: 0, endY: 0,
5841
+ width: this.destWidth, height: this.destHeight };
5842
+ obj.srcPoints = { startX: this.srcLeft, startY: this.srcTop, endX: 0, endY: 0,
5843
+ width: this.srcWidth, height: this.srcHeight };
5844
+ obj.filter = this.lowerContext.filter;
5845
+ return obj;
5846
+ };
5847
+ ImageEditor.prototype.updateUndoRedoColl = function (operation, previousObj, previousObjColl, previousPointColl, previousCropObj, previousText, currentText, previousFilter) {
5848
+ if (!this.isInitialLoading && this.allowUndoRedo) {
5849
+ if (this.currObjType.isUndoAction) {
5850
+ this.refreshUndoRedoColl();
5851
+ }
5647
5852
  this.undoRedoStep++;
5648
- this.undoRedoColl.push({ operation: operation, value: value, previousObj: previousObj, currentObj: currentObj,
5649
- zoomFactor: zoomFactor, sharpen: sharpen, bw: bw });
5853
+ var currentObj = this.getCurrentObj();
5854
+ currentObj.objColl = extend([], this.objColl, [], true);
5855
+ currentObj.pointColl = extend([], this.pointColl, [], true);
5856
+ currentObj.afterCropActions = extend([], this.afterCropActions, [], true);
5857
+ this.undoRedoColl.push({ operation: operation, previousObj: previousObj, currentObj: currentObj,
5858
+ previousObjColl: previousObjColl, currentObjColl: currentObj.objColl,
5859
+ previousPointColl: previousPointColl, currentPointColl: currentObj.pointColl,
5860
+ previousCropObj: previousCropObj, currentCropObj: extend({}, this.cropObj, {}, true),
5861
+ previousText: previousText, currentText: currentText, filter: previousFilter });
5650
5862
  if (this.undoRedoColl.length > 16) {
5651
5863
  this.undoRedoColl.splice(0, 1);
5652
5864
  this.undoRedoStep--;
@@ -5921,6 +6133,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
5921
6133
  }
5922
6134
  this.freehandDrawSelectedIndex = this.freehandDrawHoveredIndex;
5923
6135
  this.pointColl[this.freehandDrawSelectedIndex].isSelected = true;
6136
+ this.freehandDrawSelectedId = this.pointColl[this.freehandDrawSelectedIndex].id;
5924
6137
  if (this.pointColl[this.freehandDrawHoveredIndex].strokeColor !== '#42a5f5') {
5925
6138
  this.tempFreeHandDrawEditingStyles.strokeColor = this.pointColl[this.freehandDrawHoveredIndex].strokeColor;
5926
6139
  }
@@ -6213,15 +6426,16 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
6213
6426
  }
6214
6427
  if (e.currentTarget === this.upperCanvas) {
6215
6428
  this.currObjType.shape = this.currObjType.shape.toLowerCase();
6216
- if (!this.togglePen && !this.dragCanvas) {
6429
+ var prevCropObj = extend({}, this.cropObj, {}, true);
6430
+ var prevObj = this.getCurrentObj();
6431
+ prevObj.objColl = extend([], this.objColl, [], true);
6432
+ prevObj.pointColl = extend([], this.pointColl, [], true);
6433
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
6434
+ if (!this.togglePen && !isCropSelection) {
6217
6435
  if (!isNullOrUndefined(this.tempObjColl) && this.activeObj.activePoint.width !== 0) {
6218
6436
  this.objColl.push(this.activeObj);
6219
6437
  if (JSON.stringify(this.activeObj.activePoint) !== JSON.stringify(this.tempActiveObj.activePoint)) {
6220
- this.undoRedoColl.push({ operation: 'shapeTransform', value: null,
6221
- currentObj: extend([], this.objColl, [], true),
6222
- previousObj: this.tempObjColl, zoomFactor: this.zoomFactor,
6223
- sharpen: this.adjustmentLevel.sharpen, bw: this.adjustmentLevel.bw });
6224
- this.undoRedoStep++;
6438
+ this.updateUndoRedoColl('shapeTransform', prevObj, this.tempObjColl, prevObj.pointColl, prevCropObj);
6225
6439
  }
6226
6440
  this.redrawShape(this.objColl[this.objColl.length - 1]);
6227
6441
  this.tempObjColl = undefined;
@@ -6232,13 +6446,8 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
6232
6446
  }
6233
6447
  else if (isCropSelection && !this.togglePen) {
6234
6448
  if (JSON.stringify(this.activeObj.activePoint) !== JSON.stringify(this.tempActiveObj.activePoint)) {
6235
- this.undoRedoColl.push({ operation: 'selectionTransform', value: null,
6236
- currentObj: extend([], this.objColl, [], true),
6237
- previousObj: this.objColl, zoomFactor: this.zoomFactor,
6238
- currentSelectionObj: extend([], this.activeObj, {}, true),
6239
- previousSelectionObj: extend([], this.tempActiveObj, {}, true),
6240
- sharpen: this.adjustmentLevel.sharpen, bw: this.adjustmentLevel.bw });
6241
- this.undoRedoStep++;
6449
+ prevObj.activeObj = extend([], this.tempActiveObj, {}, true);
6450
+ this.updateUndoRedoColl('selectionTransform', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
6242
6451
  }
6243
6452
  }
6244
6453
  }
@@ -6269,27 +6478,34 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
6269
6478
  e.preventDefault();
6270
6479
  e.stopImmediatePropagation();
6271
6480
  break;
6272
- case (e.ctrlKey && 'z'):
6273
- if (this.allowUndoRedo) {
6274
- this.callUndo();
6275
- }
6276
- break;
6277
- case (e.ctrlKey && 'y'):
6278
- if (this.allowUndoRedo) {
6279
- this.callRedo();
6280
- }
6281
- break;
6481
+ // case (e.ctrlKey && 'z'):
6482
+ // if (this.allowUndoRedo) {
6483
+ // this.callUndo();
6484
+ // }
6485
+ // break;
6486
+ // case (e.ctrlKey && 'y'):
6487
+ // if (this.allowUndoRedo) {
6488
+ // this.callRedo();
6489
+ // }
6490
+ // break;
6282
6491
  case 'Delete':
6283
6492
  if (this.isFreehandDrawEditing) {
6284
6493
  this.updateFreehandDrawColorChange();
6285
- // eslint-disable-next-line
6286
- var previousObj = extend([], this.pointColl, [], true);
6287
- this.deleteFreehandDraw(this.freehandDrawHoveredIndex);
6288
- this.updateUndoRedoColl('delete', 'freehanddraw', previousObj, this.pointColl, this.zoomFactor);
6494
+ var prevCropObj = extend({}, this.cropObj, {}, true);
6495
+ var prevObj = this.getCurrentObj();
6496
+ prevObj.objColl = extend([], this.objColl, [], true);
6497
+ prevObj.pointColl = extend([], this.pointColl, [], true);
6498
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
6499
+ this.deleteFreehandDraw(parseInt(this.freehandDrawSelectedId.split('_')[1], 10) - 1, true);
6500
+ this.updateUndoRedoColl('deleteFreehandDrawing', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
6289
6501
  }
6290
6502
  else if (this.textArea.style.display === 'none') {
6291
6503
  this.objColl.push(this.activeObj);
6292
- var previousObj = extend([], this.objColl, [], true);
6504
+ var prevCropObj = extend({}, this.cropObj, {}, true);
6505
+ var prevObj = this.getCurrentObj();
6506
+ prevObj.objColl = extend([], this.objColl, [], true);
6507
+ prevObj.pointColl = extend([], this.pointColl, [], true);
6508
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
6293
6509
  this.objColl.pop();
6294
6510
  previousShapeSettings = this.updatePreviousShapeSettings();
6295
6511
  shapeChangingArgs = { action: 'delete', previousShapeSettings: previousShapeSettings, currentShapeSettings: null };
@@ -6297,7 +6513,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
6297
6513
  this.clearSelection();
6298
6514
  this.trigger('shapeChanging', shapeChangingArgs);
6299
6515
  this.refreshToolbar('main');
6300
- this.updateUndoRedoColl('delete', 'shape', previousObj, this.objColl, this.zoomFactor);
6516
+ this.updateUndoRedoColl('deleteObj', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
6301
6517
  }
6302
6518
  break;
6303
6519
  case 'Escape':
@@ -6352,6 +6568,10 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
6352
6568
  this.lastPan = { x: this.destLeft, y: this.destTop };
6353
6569
  if (isNullOrUndefined(this.tempPanMove)) {
6354
6570
  this.tempPanMove = { x: x, y: y };
6571
+ this.panStartObj = this.getCurrentObj();
6572
+ this.panStartObj.objColl = extend([], this.objColl, [], true);
6573
+ this.panStartObj.pointColl = extend([], this.pointColl, [], true);
6574
+ this.panStartObj.afterCropActions = this.afterCropActions;
6355
6575
  }
6356
6576
  };
6357
6577
  ImageEditor.prototype.canvasMouseMoveHandler = function (e) {
@@ -6384,10 +6604,12 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
6384
6604
  e.preventDefault();
6385
6605
  if (this.togglePan) {
6386
6606
  if (this.panDown && this.panMove && this.togglePan && this.dragCanvas) {
6607
+ var prevCropObj = extend({}, this.cropObj, {}, true);
6608
+ this.updateUndoRedoColl('pan', this.panStartObj, this.panStartObj.objColl, this.panStartObj.pointColl, prevCropObj);
6387
6609
  this.panDown = null;
6388
6610
  this.panMove = null;
6389
6611
  this.tempPanMove = null;
6390
- this.updateUndoRedoColl('pan', null, { x: this.lastPan.x, y: this.lastPan.y }, { x: this.destLeft, y: this.destTop });
6612
+ this.panStartObj = null;
6391
6613
  }
6392
6614
  }
6393
6615
  this.currObjType.isDragging = false;
@@ -6700,7 +6922,12 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
6700
6922
  };
6701
6923
  ImageEditor.prototype.updateTextFromTextArea = function () {
6702
6924
  if (this.activeObj.keyHistory !== this.textArea.value) {
6703
- this.updateUndoRedoColl('text', this.objColl, this.activeObj.keyHistory, this.textArea.value, this.zoomFactor, this.adjustmentLevel.sharpen, this.adjustmentLevel.bw);
6925
+ var prevCropObj = extend({}, this.cropObj, {}, true);
6926
+ var prevObj = this.getCurrentObj();
6927
+ prevObj.objColl = extend([], this.objColl, [], true);
6928
+ prevObj.pointColl = extend([], this.pointColl, [], true);
6929
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
6930
+ this.updateUndoRedoColl('text', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj, this.activeObj.keyHistory, this.textArea.value);
6704
6931
  }
6705
6932
  this.activeObj.keyHistory = this.textArea.value;
6706
6933
  this.textArea.style.display = 'none';
@@ -6981,7 +7208,6 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
6981
7208
  this.refreshActiveObj();
6982
7209
  this.lowerContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
6983
7210
  this.redrawImgWithObj();
6984
- //this.zoomFreehandDrawColl();
6985
7211
  if ((!isNullOrUndefined(this.currSelectionPoint) && this.currSelectionPoint.shape === 'crop-circle') || this.isCircleCrop) {
6986
7212
  this.cropCircle(this.lowerContext);
6987
7213
  }
@@ -8185,6 +8411,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
8185
8411
  this.activeObj = extend({}, tempObj, {}, true);
8186
8412
  };
8187
8413
  ImageEditor.prototype.drawObject = function (canvas, obj, isCropRatio, points, isPreventDrag, saveContext) {
8414
+ this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
8188
8415
  var canvasDraw;
8189
8416
  if (canvas.toLowerCase() === 'original') {
8190
8417
  canvasDraw = this.lowerContext;
@@ -9935,28 +10162,6 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
9935
10162
  height: this.destHeight / this.objColl[i].activePoint.height };
9936
10163
  }
9937
10164
  };
9938
- ImageEditor.prototype.setTextFontSize = function (obj) {
9939
- if (obj.shape === 'text') {
9940
- var maxText = this.getMaxText(null, obj.keyHistory);
9941
- var degree = void 0;
9942
- if (obj.shapeDegree === 0) {
9943
- degree = this.degree;
9944
- }
9945
- else {
9946
- degree = this.degree - obj.shapeDegree;
9947
- }
9948
- var multiplier = 2;
9949
- if (maxText.length === 1) {
9950
- multiplier = 1;
9951
- }
9952
- if (degree === 0 || degree === 180 || degree === -180) {
9953
- obj.textSettings.fontSize = (obj.activePoint.width / maxText.length) * multiplier;
9954
- }
9955
- else {
9956
- obj.textSettings.fontSize = (obj.activePoint.height / maxText.length) * multiplier;
9957
- }
9958
- }
9959
- };
9960
10165
  ImageEditor.prototype.redrawShape = function (obj) {
9961
10166
  for (var i = 0; i < this.objColl.length; i++) {
9962
10167
  if (JSON.stringify(obj) === JSON.stringify(this.objColl[i])) {
@@ -10157,7 +10362,10 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
10157
10362
  }
10158
10363
  this.togglePen = false;
10159
10364
  this.redrawActObj();
10160
- var objColl = extend([], this.objColl, [], true);
10365
+ var prevObj = this.getCurrentObj();
10366
+ prevObj.objColl = extend([], this.objColl, [], true);
10367
+ prevObj.pointColl = extend([], this.pointColl, [], true);
10368
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
10161
10369
  this.keyHistory = '';
10162
10370
  this.refreshActiveObj();
10163
10371
  this.activeObj.shape = 'text';
@@ -10221,10 +10429,8 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
10221
10429
  this.activeObj.textFlip = this.currFlipState;
10222
10430
  this.updateFontRatio(this.activeObj);
10223
10431
  this.objColl.push(this.activeObj);
10224
- this.undoRedoColl.push({ operation: 'shapeTransform', value: null,
10225
- currentObj: extend([], this.objColl, [], true), previousObj: objColl, zoomFactor: this.zoomFactor,
10226
- sharpen: this.adjustmentLevel.sharpen, bw: this.adjustmentLevel.bw });
10227
- this.undoRedoStep++;
10432
+ var prevCropObj = extend({}, this.cropObj, {}, true);
10433
+ this.updateUndoRedoColl('shapeTransform', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
10228
10434
  this.redrawShape(this.objColl[this.objColl.length - 1]);
10229
10435
  this.isShapeInserted = true;
10230
10436
  this.refreshToolbar('text');
@@ -10369,6 +10575,43 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
10369
10575
  }
10370
10576
  }
10371
10577
  this.freehandRedraw(this.lowerContext);
10578
+ this.updateCurrSelectionPoint(degree);
10579
+ };
10580
+ ImageEditor.prototype.updateCurrSelectionPoint = function (degree) {
10581
+ if (!isNullOrUndefined(this.currSelectionPoint) && !isNullOrUndefined(this.currDestinationPoint)) {
10582
+ var activeObj = extend({}, this.activeObj, {}, true);
10583
+ var objColl = extend([], this.objColl, [], true);
10584
+ var srcPoints = { startX: this.srcLeft, startY: this.srcTop, width: this.srcWidth, height: this.srcHeight };
10585
+ var destPoints = { startX: this.destLeft, startY: this.destTop, width: this.destWidth, height: this.destHeight };
10586
+ this.objColl = [];
10587
+ this.objColl.push(extend({}, this.currSelectionPoint, {}, true));
10588
+ this.srcLeft = 0;
10589
+ this.srcTop = 0;
10590
+ this.srcWidth = this.baseImg.width;
10591
+ this.srcHeight = this.baseImg.height;
10592
+ this.destLeft = this.currDestinationPoint.startX;
10593
+ this.destTop = this.currDestinationPoint.startY;
10594
+ this.destWidth = this.currDestinationPoint.width;
10595
+ this.destHeight = this.currDestinationPoint.height;
10596
+ if (typeof (degree) === 'number') {
10597
+ this.setDestinationPoints();
10598
+ this.setClientTransformedDimension();
10599
+ }
10600
+ this.objColl[0].shapeFlip = '';
10601
+ this.redrawObj(degree);
10602
+ this.currSelectionPoint = extend({}, this.objColl[0], {}, true);
10603
+ this.currDestinationPoint = { startX: this.destLeft, startY: this.destTop, width: this.destWidth, height: this.destHeight };
10604
+ this.objColl = objColl;
10605
+ this.activeObj = activeObj;
10606
+ this.srcLeft = srcPoints.startX;
10607
+ this.srcTop = srcPoints.startY;
10608
+ this.srcWidth = srcPoints.width;
10609
+ this.srcHeight = srcPoints.height;
10610
+ this.destLeft = destPoints.startX;
10611
+ this.destTop = destPoints.startY;
10612
+ this.destWidth = destPoints.width;
10613
+ this.destHeight = destPoints.height;
10614
+ }
10372
10615
  };
10373
10616
  ImageEditor.prototype.setClientTransformedDimension = function (isPreventDimension) {
10374
10617
  if (this.degree % 90 === 0 && this.degree % 180 !== 0) {
@@ -10385,100 +10628,110 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
10385
10628
  }
10386
10629
  }
10387
10630
  };
10388
- ImageEditor.prototype.popForDefaultTransformedState = function () {
10631
+ ImageEditor.prototype.popForDefaultTransformedState = function (collection) {
10389
10632
  var rotateRight = 0;
10390
10633
  var rotateleft = 0;
10391
10634
  var horizontal = 0;
10392
10635
  var vertical = 0;
10393
- for (var i = 0; i < this.rotateFlipColl.length; i++) {
10394
- if (this.rotateFlipColl[i] === 90) {
10636
+ for (var i = 0; i < collection.length; i++) {
10637
+ if (collection[i] === 90 || collection[i] === 'rotateRight') {
10395
10638
  rotateRight++;
10396
10639
  rotateleft = 0;
10397
10640
  horizontal = 0;
10398
10641
  vertical = 0;
10399
10642
  if (rotateRight === 4) {
10400
- this.rotateFlipColl.pop();
10401
- this.rotateFlipColl.pop();
10402
- this.rotateFlipColl.pop();
10403
- this.rotateFlipColl.pop();
10643
+ collection.pop();
10644
+ collection.pop();
10645
+ collection.pop();
10646
+ collection.pop();
10404
10647
  }
10405
10648
  }
10406
- else if (this.rotateFlipColl[i] === -90) {
10649
+ else if (collection[i] === -90 || collection[i] === 'rotateLeft') {
10407
10650
  rotateleft++;
10408
10651
  rotateRight = 0;
10409
10652
  horizontal = 0;
10410
10653
  vertical = 0;
10411
10654
  if (rotateleft === 4) {
10412
- this.rotateFlipColl.pop();
10413
- this.rotateFlipColl.pop();
10414
- this.rotateFlipColl.pop();
10415
- this.rotateFlipColl.pop();
10655
+ collection.pop();
10656
+ collection.pop();
10657
+ collection.pop();
10658
+ collection.pop();
10416
10659
  }
10417
10660
  }
10418
- else if (this.rotateFlipColl[i] === 'horizontal') {
10661
+ else if (collection[i] === 'horizontal' || collection[i] === 'horizontalflip') {
10419
10662
  horizontal++;
10420
10663
  rotateleft = 0;
10421
10664
  rotateRight = 0;
10422
10665
  vertical = 0;
10423
10666
  if (horizontal === 2) {
10424
- this.rotateFlipColl.pop();
10425
- this.rotateFlipColl.pop();
10667
+ collection.pop();
10668
+ collection.pop();
10426
10669
  }
10427
10670
  }
10428
- else if (this.rotateFlipColl[i] === 'vertical') {
10671
+ else if (collection[i] === 'vertical' || collection[i] === 'verticalflip') {
10429
10672
  vertical++;
10430
10673
  horizontal = 0;
10431
10674
  rotateleft = 0;
10432
10675
  rotateRight = 0;
10433
10676
  if (vertical === 2) {
10434
- this.rotateFlipColl.pop();
10435
- this.rotateFlipColl.pop();
10677
+ collection.pop();
10678
+ collection.pop();
10436
10679
  }
10437
10680
  }
10438
10681
  }
10682
+ return collection;
10439
10683
  };
10440
- ImageEditor.prototype.popForDefaultFlipState = function () {
10441
- for (var i = 0; i < this.rotateFlipColl.length; i++) {
10442
- if (!isNullOrUndefined(this.rotateFlipColl[i + 3])) {
10443
- if (this.rotateFlipColl[i] === 'horizontal' && this.rotateFlipColl[i + 1] === 'vertical' &&
10444
- this.rotateFlipColl[i + 2] === 'horizontal' && this.rotateFlipColl[i + 3] === 'vertical') {
10445
- this.rotateFlipColl.pop();
10446
- this.rotateFlipColl.pop();
10447
- this.rotateFlipColl.pop();
10448
- this.rotateFlipColl.pop();
10684
+ ImageEditor.prototype.popForDefaultFlipState = function (collection) {
10685
+ for (var i = 0; i < collection.length; i++) {
10686
+ if (!isNullOrUndefined(collection[i + 3])) {
10687
+ if ((collection[i] === 'horizontal' || collection[i] === 'horizontalFlip')
10688
+ && (collection[i + 1] === 'vertical' || collection[i] === 'verticalFlip') &&
10689
+ (collection[i + 2] === 'horizontal' || collection[i] === 'horizontalFlip') &&
10690
+ (collection[i + 3] === 'vertical' || collection[i] === 'verticalFlip')) {
10691
+ collection.pop();
10692
+ collection.pop();
10693
+ collection.pop();
10694
+ collection.pop();
10449
10695
  }
10450
- else if (this.rotateFlipColl[i] === 'vertical' && this.rotateFlipColl[i + 1] === 'horizontal' &&
10451
- this.rotateFlipColl[i + 2] === 'vertical' && this.rotateFlipColl[i + 3] === 'horizontal') {
10452
- this.rotateFlipColl.pop();
10453
- this.rotateFlipColl.pop();
10454
- this.rotateFlipColl.pop();
10455
- this.rotateFlipColl.pop();
10696
+ else if ((collection[i] === 'vertical' || collection[i] === 'verticalFlip')
10697
+ && (collection[i + 1] === 'horizontal' || collection[i + 1] === 'horizontalFlip') &&
10698
+ (collection[i + 2] === 'vertical' || collection[i] === 'verticalFlip') &&
10699
+ (collection[i + 3] === 'horizontal' || collection[i] === 'horizontalFlip')) {
10700
+ collection.pop();
10701
+ collection.pop();
10702
+ collection.pop();
10703
+ collection.pop();
10456
10704
  }
10457
10705
  }
10458
10706
  }
10707
+ return collection;
10459
10708
  };
10460
- ImageEditor.prototype.popForDefaultRotateState = function () {
10461
- for (var i = 0; i < this.rotateFlipColl.length; i++) {
10462
- if (!isNullOrUndefined(this.rotateFlipColl[i + 1])) {
10463
- if (this.rotateFlipColl[i] === 90 && this.rotateFlipColl[i + 1] === -90) {
10464
- this.rotateFlipColl.pop();
10465
- this.rotateFlipColl.pop();
10709
+ ImageEditor.prototype.popForDefaultRotateState = function (collection) {
10710
+ for (var i = 0; i < collection.length; i++) {
10711
+ if (!isNullOrUndefined(collection[i + 1])) {
10712
+ if ((collection[i] === 90 || collection[i] === 'rotateRight') &&
10713
+ (collection[i + 1] === -90 || collection[i] === 'rotateLeft')) {
10714
+ collection.pop();
10715
+ collection.pop();
10466
10716
  }
10467
- else if (this.rotateFlipColl[i] === -90 && this.rotateFlipColl[i + 1] === 90) {
10468
- this.rotateFlipColl.pop();
10469
- this.rotateFlipColl.pop();
10717
+ else if ((collection[i] === -90 || collection[i] === 'rotateLeft') &&
10718
+ (collection[i + 1] === 90 || collection[i] === 'rotateRight')) {
10719
+ collection.pop();
10720
+ collection.pop();
10470
10721
  }
10471
10722
  }
10472
10723
  }
10724
+ return collection;
10473
10725
  };
10474
- ImageEditor.prototype.alignRotateFlipColl = function () {
10475
- this.popForDefaultTransformedState();
10476
- this.popForDefaultFlipState();
10477
- this.popForDefaultRotateState();
10478
- if (this.rotateFlipColl.length === 0) {
10726
+ ImageEditor.prototype.alignRotateFlipColl = function (collection, isRotateFlipCollection) {
10727
+ collection = this.popForDefaultTransformedState(collection);
10728
+ collection = this.popForDefaultFlipState(collection);
10729
+ collection = this.popForDefaultRotateState(collection);
10730
+ if (collection.length === 0 && isRotateFlipCollection) {
10479
10731
  this.degree = 0;
10480
10732
  this.currFlipState = '';
10481
10733
  }
10734
+ return collection;
10482
10735
  };
10483
10736
  ImageEditor.prototype.updateFlipColl = function (direction) {
10484
10737
  if (this.flipColl.length === 0) {
@@ -10649,35 +10902,51 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
10649
10902
  this.applyPenDraw();
10650
10903
  this.adjustmentLevel.brightness = value;
10651
10904
  value = this.getFilterValue(value);
10652
- var temp = this.lowerContext.filter;
10905
+ var prevCropObj = extend({}, this.cropObj, {}, true);
10906
+ var prevObj = this.getCurrentObj();
10907
+ prevObj.objColl = extend([], this.objColl, [], true);
10908
+ prevObj.pointColl = extend([], this.pointColl, [], true);
10909
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
10653
10910
  this.updateAdjustment('brightness', value);
10654
- this.updateUndoRedoColl('brightness', value, temp, this.lowerContext.filter, this.zoomFactor, this.adjustmentLevel.sharpen, this.adjustmentLevel.bw);
10911
+ this.updateUndoRedoColl('brightness', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
10655
10912
  };
10656
10913
  ImageEditor.prototype.setContrast = function (value) {
10657
10914
  this.applyPenDraw();
10658
10915
  this.adjustmentLevel.contrast = value;
10659
- var temp = this.lowerContext.filter;
10660
10916
  value = this.getFilterValue(value);
10661
10917
  value *= 100;
10918
+ var prevCropObj = extend({}, this.cropObj, {}, true);
10919
+ var prevObj = this.getCurrentObj();
10920
+ prevObj.objColl = extend([], this.objColl, [], true);
10921
+ prevObj.pointColl = extend([], this.pointColl, [], true);
10922
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
10662
10923
  this.updateAdjustment('contrast', value);
10663
- this.updateUndoRedoColl('contrast', value, temp, this.lowerContext.filter, this.zoomFactor, this.adjustmentLevel.sharpen, this.adjustmentLevel.bw);
10924
+ this.updateUndoRedoColl('contrast', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
10664
10925
  };
10665
10926
  ImageEditor.prototype.setHue = function (value) {
10666
10927
  this.applyPenDraw();
10667
10928
  this.adjustmentLevel.hue = value;
10668
10929
  value *= 3;
10669
- var temp = this.lowerContext.filter;
10930
+ var prevCropObj = extend({}, this.cropObj, {}, true);
10931
+ var prevObj = this.getCurrentObj();
10932
+ prevObj.objColl = extend([], this.objColl, [], true);
10933
+ prevObj.pointColl = extend([], this.pointColl, [], true);
10934
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
10670
10935
  this.updateAdjustment('hue', value);
10671
- this.updateUndoRedoColl('hue', value, temp, this.lowerContext.filter, this.zoomFactor, this.adjustmentLevel.sharpen, this.adjustmentLevel.bw);
10936
+ this.updateUndoRedoColl('hue', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
10672
10937
  };
10673
10938
  ImageEditor.prototype.setSaturation = function (value) {
10674
10939
  this.applyPenDraw();
10675
10940
  this.adjustmentLevel.saturation = value;
10676
10941
  value = this.getSaturationFilterValue(value);
10677
10942
  value *= 100;
10678
- var temp = this.lowerContext.filter;
10943
+ var prevCropObj = extend({}, this.cropObj, {}, true);
10944
+ var prevObj = this.getCurrentObj();
10945
+ prevObj.objColl = extend([], this.objColl, [], true);
10946
+ prevObj.pointColl = extend([], this.pointColl, [], true);
10947
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
10679
10948
  this.updateAdjustment('saturation', value);
10680
- this.updateUndoRedoColl('saturation', value, temp, this.lowerContext.filter, this.zoomFactor, this.adjustmentLevel.sharpen, this.adjustmentLevel.bw);
10949
+ this.updateUndoRedoColl('saturation', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
10681
10950
  };
10682
10951
  ImageEditor.prototype.setOpacity = function (value) {
10683
10952
  this.applyPenDraw();
@@ -10700,9 +10969,13 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
10700
10969
  else if (value === 0) {
10701
10970
  value = 0.25;
10702
10971
  }
10703
- var temp = this.lowerContext.filter;
10972
+ var prevCropObj = extend({}, this.cropObj, {}, true);
10973
+ var prevObj = this.getCurrentObj();
10974
+ prevObj.objColl = extend([], this.objColl, [], true);
10975
+ prevObj.pointColl = extend([], this.pointColl, [], true);
10976
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
10704
10977
  this.updateAdjustment('opacity', value);
10705
- this.updateUndoRedoColl('opacity', value, temp, this.lowerContext.filter, this.zoomFactor, this.adjustmentLevel.sharpen, this.adjustmentLevel.bw);
10978
+ this.updateUndoRedoColl('opacity', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
10706
10979
  };
10707
10980
  ImageEditor.prototype.setBlur = function (value) {
10708
10981
  this.applyPenDraw();
@@ -10710,25 +10983,37 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
10710
10983
  value /= 20;
10711
10984
  // Since 0.5 is not working in blur we consider from 1
10712
10985
  value += 0.5;
10713
- var temp = this.lowerContext.filter;
10986
+ var prevCropObj = extend({}, this.cropObj, {}, true);
10987
+ var prevObj = this.getCurrentObj();
10988
+ prevObj.objColl = extend([], this.objColl, [], true);
10989
+ prevObj.pointColl = extend([], this.pointColl, [], true);
10990
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
10714
10991
  this.updateAdjustment('blur', value);
10715
- this.updateUndoRedoColl('blur', value, temp, this.lowerContext.filter, this.zoomFactor, this.adjustmentLevel.sharpen, this.adjustmentLevel.bw);
10992
+ this.updateUndoRedoColl('blur', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
10716
10993
  };
10717
10994
  ImageEditor.prototype.setExposure = function (value) {
10718
10995
  this.applyPenDraw();
10719
10996
  this.adjustmentLevel.exposure = value;
10720
10997
  value = this.getFilterValue(value);
10721
- var temp = this.lowerContext.filter;
10998
+ var prevCropObj = extend({}, this.cropObj, {}, true);
10999
+ var prevObj = this.getCurrentObj();
11000
+ prevObj.objColl = extend([], this.objColl, [], true);
11001
+ prevObj.pointColl = extend([], this.pointColl, [], true);
11002
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
10722
11003
  this.updateAdjustment('exposure', value);
10723
- this.updateUndoRedoColl('exposure', value, temp, this.lowerContext.filter, this.zoomFactor, this.adjustmentLevel.sharpen, this.adjustmentLevel.bw);
11004
+ this.updateUndoRedoColl('exposure', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
10724
11005
  };
10725
11006
  ImageEditor.prototype.setFilter = function (type) {
10726
11007
  type = type.toLowerCase();
10727
11008
  this.applyPenDraw();
10728
- var tempFilter = this.lowerContext.filter;
10729
11009
  var prevFilter = this.currentFilter;
11010
+ var prevCropObj = extend({}, this.cropObj, {}, true);
11011
+ var prevObj = this.getCurrentObj();
11012
+ prevObj.objColl = extend([], this.objColl, [], true);
11013
+ prevObj.pointColl = extend([], this.pointColl, [], true);
11014
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
10730
11015
  this.updateAdjustment(type, null);
10731
- this.updateUndoRedoColl(type, prevFilter, tempFilter, this.lowerContext.filter, this.zoomFactor, this.adjustmentLevel.sharpen, this.adjustmentLevel.bw);
11016
+ this.updateUndoRedoColl(type, prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj, null, null, prevFilter);
10732
11017
  };
10733
11018
  ImageEditor.prototype.renderImage = function () {
10734
11019
  var temp = this.lowerContext.filter;
@@ -10763,8 +11048,81 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
10763
11048
  this.updateFontStyles();
10764
11049
  this.textArea.style.width = this.activeObj.activePoint.width + 'px';
10765
11050
  };
11051
+ ImageEditor.prototype.drawNewSelection = function (type, startX, startY, width, height) {
11052
+ var points;
11053
+ var cropShape = 'crop-' + type;
11054
+ if (cropShape.toLowerCase() === 'crop-custom') {
11055
+ if (this.currObjType.shape === '') {
11056
+ this.drawCustomSelection('crop-custom');
11057
+ }
11058
+ if (startX && startY) {
11059
+ this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
11060
+ this.currObjType.shape = this.activeObj.shape = cropShape.toLowerCase();
11061
+ this.activeObj.activePoint.startX = startX;
11062
+ this.activeObj.activePoint.startY = startY;
11063
+ this.activeObj.activePoint.endX = this.lowerCanvas.width;
11064
+ this.activeObj.activePoint.endY = this.lowerCanvas.height;
11065
+ this.activeObj.activePoint.width = this.activeObj.activePoint.endX - this.activeObj.activePoint.startX;
11066
+ this.activeObj.activePoint.height = this.activeObj.activePoint.endY - this.activeObj.activePoint.startY;
11067
+ this.drawObject('duplicate');
11068
+ }
11069
+ }
11070
+ else if (cropShape.toLowerCase() === 'crop-canvas') {
11071
+ this.upperCanvas.style.display = 'none';
11072
+ this.dragCanvas = true;
11073
+ }
11074
+ else {
11075
+ this.currObjType.isCustomCrop = false;
11076
+ this.currObjType.shape = cropShape.toLowerCase();
11077
+ if (width && height) {
11078
+ points = { startX: startX, startY: startY, endX: startX + width, endY: startY + height,
11079
+ width: width, height: height };
11080
+ }
11081
+ else if (width && cropShape === 'crop-circle') {
11082
+ points = { startX: startX, startY: startY, endX: startX + width, endY: startY + width,
11083
+ width: width, height: width };
11084
+ }
11085
+ this.activeObj.shape = cropShape.toLowerCase();
11086
+ this.drawObject('duplicate', null, true, points);
11087
+ }
11088
+ };
11089
+ ImageEditor.prototype.setDestPointsForFlipState = function (isUpdate) {
11090
+ if (this.getCurrentPanRegion() !== '') {
11091
+ if (this.getCurrentPanRegion() === 'horizontal') {
11092
+ this.destLeft = this.lowerCanvas.clientWidth - (this.destWidth + this.destLeft);
11093
+ }
11094
+ else if (this.getCurrentPanRegion() === 'vertical') {
11095
+ this.destTop = this.lowerCanvas.clientHeight - (this.destHeight + this.destTop);
11096
+ }
11097
+ else {
11098
+ this.destLeft = this.lowerCanvas.clientWidth - (this.destWidth + this.destLeft);
11099
+ this.destTop = this.lowerCanvas.clientHeight - (this.destHeight + this.destTop);
11100
+ }
11101
+ }
11102
+ };
11103
+ ImageEditor.prototype.performUndoDefaultAction = function (obj) {
11104
+ this.lowerContext.filter = obj.previousObj.filter;
11105
+ this.objColl = [];
11106
+ this.pointColl = [];
11107
+ this.freehandCounter = 0;
11108
+ this.setCurrentObj(obj.previousObj);
11109
+ this.destLeft = obj.previousObj.destPoints.startX;
11110
+ this.destTop = obj.previousObj.destPoints.startY;
11111
+ var activeObj = extend({}, this.activeObj, {}, true);
11112
+ this.objColl = extend([], obj.previousObjColl, [], true);
11113
+ this.pointColl = extend([], obj.previousPointColl, [], true);
11114
+ this.freehandCounter = this.pointColl.length;
11115
+ this.lowerContext.filter = 'none';
11116
+ this.iterateObjColl();
11117
+ this.freehandRedraw(this.lowerContext);
11118
+ this.lowerContext.filter = obj.previousObj.filter;
11119
+ this.activeObj = activeObj;
11120
+ this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
11121
+ if (this.activeObj.activePoint.width !== 0 && this.activeObj.activePoint.height !== 0) {
11122
+ this.drawObject('duplicate');
11123
+ }
11124
+ };
10766
11125
  ImageEditor.prototype.setAdjustment = function (type) {
10767
- this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
10768
11126
  var splitWords = this.lowerContext.filter.split(' ');
10769
11127
  var value;
10770
11128
  var valueArr;
@@ -10827,59 +11185,25 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
10827
11185
  this.adjustmentLevel.exposure = this.setFilterValue(value);
10828
11186
  break;
10829
11187
  }
10830
- this.callUpdateCurrentTransformedState();
10831
- };
10832
- ImageEditor.prototype.updateFilter = function (obj) {
10833
- var selEle = this.element.querySelector('.e-contextual-toolbar-wrapper .e-toolbar-item.e-selected');
10834
- if (selEle) {
10835
- selEle.classList.remove('e-selected');
10836
- }
10837
- var filterCanvas = document.getElementById(obj.value + 'Canvas');
10838
- if (filterCanvas) {
10839
- filterCanvas.parentElement.classList.add('e-selected');
10840
- }
10841
- this.currentFilter = obj.value;
10842
- this.lowerContext.filter = this.canvasFilter = obj.previousObj;
10843
- this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
10844
- this.isUndoRedo = true;
10845
- this.redrawImgWithObj();
10846
11188
  };
10847
- ImageEditor.prototype.drawNewSelection = function (type, startX, startY, width, height) {
10848
- var points;
10849
- var cropShape = 'crop-' + type;
10850
- if (cropShape.toLowerCase() === 'crop-custom') {
10851
- if (this.currObjType.shape === '') {
10852
- this.drawCustomSelection('crop-custom');
11189
+ ImageEditor.prototype.updateFilter = function (type, previousFilter) {
11190
+ if (type === 'default' || type === 'chrome' || type === 'cold' ||
11191
+ type === 'warm' || type === 'grayscale' || type === 'blackandwhite' ||
11192
+ type === 'sepia' || type === 'invert' || type === 'sharpen') {
11193
+ var selEle = this.element.querySelector('.e-contextual-toolbar-wrapper .e-toolbar-item.e-selected');
11194
+ if (selEle) {
11195
+ selEle.classList.remove('e-selected');
10853
11196
  }
10854
- if (startX && startY) {
10855
- this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
10856
- this.currObjType.shape = this.activeObj.shape = cropShape.toLowerCase();
10857
- this.activeObj.activePoint.startX = startX;
10858
- this.activeObj.activePoint.startY = startY;
10859
- this.activeObj.activePoint.endX = this.lowerCanvas.width;
10860
- this.activeObj.activePoint.endY = this.lowerCanvas.height;
10861
- this.activeObj.activePoint.width = this.activeObj.activePoint.endX - this.activeObj.activePoint.startX;
10862
- this.activeObj.activePoint.height = this.activeObj.activePoint.endY - this.activeObj.activePoint.startY;
10863
- this.drawObject('duplicate');
11197
+ var filterCanvas = document.getElementById(this.element.id + '_' + type + 'Canvas');
11198
+ if (filterCanvas) {
11199
+ filterCanvas.parentElement.classList.add('e-selected');
10864
11200
  }
10865
- }
10866
- else if (cropShape.toLowerCase() === 'crop-canvas') {
10867
- this.upperCanvas.style.display = 'none';
10868
- this.dragCanvas = true;
10869
- }
10870
- else {
10871
- this.currObjType.isCustomCrop = false;
10872
- this.currObjType.shape = cropShape.toLowerCase();
10873
- if (width && height) {
10874
- points = { startX: startX, startY: startY, endX: startX + width, endY: startY + height,
10875
- width: width, height: height };
11201
+ if (!isNullOrUndefined(previousFilter)) {
11202
+ this.currentFilter = previousFilter;
10876
11203
  }
10877
- else if (width && cropShape === 'crop-circle') {
10878
- points = { startX: startX, startY: startY, endX: startX + width, endY: startY + width,
10879
- width: width, height: width };
11204
+ else {
11205
+ this.currentFilter = this.element.id + '_' + type;
10880
11206
  }
10881
- this.activeObj.shape = cropShape.toLowerCase();
10882
- this.drawObject('duplicate', null, true, points);
10883
11207
  }
10884
11208
  };
10885
11209
  /**
@@ -10920,11 +11244,15 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
10920
11244
  }
10921
11245
  if (!this.disabled && this.activeObj.horTopLine !== undefined && (this.currObjType.isCustomCrop || splitWords[0] === 'crop')) {
10922
11246
  isCrop = true;
10923
- var shape = this.activeObj.shape;
11247
+ var prevCropObj = extend({}, this.cropObj, {}, true);
11248
+ var prevObj = this.getCurrentObj();
11249
+ prevObj.objColl = extend([], this.objColl, [], true);
11250
+ prevObj.pointColl = extend([], this.pointColl, [], true);
11251
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
10924
11252
  this.cropImg();
10925
11253
  this.zoomFactor = 0;
10926
11254
  this.enableDisableToolbarBtn();
10927
- this.updateUndoRedoColl('crop', shape);
11255
+ this.updateUndoRedoColl('crop', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
10928
11256
  }
10929
11257
  }
10930
11258
  return isCrop;
@@ -10937,9 +11265,17 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
10937
11265
  */
10938
11266
  ImageEditor.prototype.flip = function (direction) {
10939
11267
  if (!this.disabled && this.isImageLoaded) {
10940
- var zoomFactor = this.zoomFactor;
10941
11268
  var transitionArgs = { direction: direction };
10942
11269
  this.trigger('flipping', transitionArgs);
11270
+ var prevCropObj = extend({}, this.cropObj, {}, true);
11271
+ var prevObj = void 0;
11272
+ if (isNullOrUndefined(this.transformCurrentObj)) {
11273
+ prevObj = this.getCurrentObj();
11274
+ prevObj.objColl = extend([], this.objColl, null, true);
11275
+ prevObj.pointColl = extend({}, this.pointColl, null, true);
11276
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
11277
+ }
11278
+ this.afterCropActions.push(direction.toLowerCase() === 'horizontal' ? 'horizontalflip' : 'verticalflip');
10943
11279
  var splitWords = [];
10944
11280
  var activeObjShape = void 0;
10945
11281
  if (!isNullOrUndefined(this.activeObj.activePoint)) {
@@ -10998,7 +11334,12 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
10998
11334
  this.rotateFlipColl.push(direction.toLowerCase());
10999
11335
  }
11000
11336
  if (this.rotateFlipColl.length === 1) {
11001
- this.setClientTransformedDimension();
11337
+ if (this.getCurrentPanRegion() === '') {
11338
+ this.setClientTransformedDimension();
11339
+ }
11340
+ else {
11341
+ this.setDestPointsForFlipState();
11342
+ }
11002
11343
  }
11003
11344
  if (this.isCircleCrop) {
11004
11345
  this.cropCircle(this.lowerContext);
@@ -11037,8 +11378,9 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11037
11378
  }
11038
11379
  this.lowerContext.filter = tempFilter;
11039
11380
  this.refreshActiveObj();
11040
- if (!this.isUndoRedo) {
11041
- this.updateUndoRedoColl('flip', direction, this.objColl, null, zoomFactor, this.adjustmentLevel.sharpen, this.adjustmentLevel.bw);
11381
+ this.updateCurrSelectionPoint(direction.toLowerCase());
11382
+ if (!this.isUndoRedo && isNullOrUndefined(this.transformCurrentObj)) {
11383
+ this.updateUndoRedoColl('flip', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
11042
11384
  }
11043
11385
  this.isUndoRedo = false;
11044
11386
  this.clearOuterCanvas(this.lowerContext);
@@ -11058,7 +11400,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11058
11400
  else if (!this.isReverseFlip) {
11059
11401
  this.refreshToolbar('main', true, true);
11060
11402
  }
11061
- this.alignRotateFlipColl();
11403
+ this.rotateFlipColl = this.alignRotateFlipColl(this.rotateFlipColl, true);
11062
11404
  }
11063
11405
  };
11064
11406
  /**
@@ -11220,17 +11562,16 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11220
11562
  this.selectedFreehandColor = '#42a5f5';
11221
11563
  this.isFreehandDrawCustomized = false;
11222
11564
  this.isShapeInserted = false;
11223
- this.tempActObj = undefined;
11224
- this.lastPan = { x: 0, y: 0 };
11565
+ this.isAllowCropPan = false;
11566
+ this.tempPannedPoint = { x: 0, y: 0 };
11225
11567
  this.currObjType = { shape: '', isDragging: false, isActiveObj: false, isText: false, isInitialText: false, isLine: false,
11226
11568
  isInitialLine: false, isCustomCrop: false, isZoomed: false, isUndoZoom: false,
11227
11569
  isUndoAction: false, isFiltered: false, isSave: false };
11228
- this.isAllowCropPan = false;
11229
- this.tempPannedPoint = { x: 0, y: 0 };
11230
11570
  this.cropObj = { cropZoom: 0, defaultZoom: 0, totalPannedPoint: { x: 0, y: 0 }, totalPannedClientPoint: { x: 0, y: 0 },
11231
- totalPannedInternalPoint: { x: 0, y: 0 }, activeObj: {}, rotateFlipColl: [], degree: 0,
11232
- currFlipState: '', destPoints: { startX: 0, startY: 0, width: 0, height: 0 },
11233
- srcPoints: { startX: 0, startY: 0, width: 0, height: 0 } };
11571
+ totalPannedInternalPoint: { x: 0, y: 0 }, tempFlipPanPoint: { x: 0, y: 0 }, activeObj: {},
11572
+ rotateFlipColl: [], degree: 0, currFlipState: '',
11573
+ destPoints: { startX: 0, startY: 0, width: 0, height: 0 },
11574
+ srcPoints: { startX: 0, startY: 0, width: 0, height: 0 }, filter: '' };
11234
11575
  this.afterCropActions = [];
11235
11576
  this.isCancelAction = this.preventZoomBtn = this.isFreehandPointMoved = false;
11236
11577
  this.isTouch = false;
@@ -11240,6 +11581,11 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11240
11581
  this.tempCurrentFreehandDrawIndex = 0;
11241
11582
  this.cancelObjColl = [];
11242
11583
  this.cancelPointColl = [];
11584
+ this.freehandDrawSelectedId = null;
11585
+ this.transformCurrentObj = null;
11586
+ this.rotatedFlipCropSelection = false;
11587
+ this.panStartObj = null;
11588
+ this.currDestinationPoint = null;
11243
11589
  this.updateCanvas();
11244
11590
  this.refreshDropDownBtn(false);
11245
11591
  this.enableDisableToolbarBtn();
@@ -11259,6 +11605,15 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11259
11605
  isRotate = true;
11260
11606
  var transitionArgs = { degree: degree };
11261
11607
  this.trigger('rotating', transitionArgs);
11608
+ var prevCropObj = extend({}, this.cropObj, {}, true);
11609
+ var prevObj = void 0;
11610
+ if (isNullOrUndefined(this.transformCurrentObj)) {
11611
+ prevObj = this.getCurrentObj();
11612
+ prevObj.objColl = extend([], this.objColl, null, true);
11613
+ prevObj.pointColl = extend({}, this.pointColl, null, true);
11614
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
11615
+ }
11616
+ this.afterCropActions.push(degree === 90 ? 'rotateRight' : 'rotateLeft');
11262
11617
  var splitWords = [];
11263
11618
  var activeObjShape = void 0;
11264
11619
  if (!isNullOrUndefined(this.activeObj.activePoint) && !isNullOrUndefined(this.activeObj.shape)) {
@@ -11274,7 +11629,6 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11274
11629
  }
11275
11630
  this.redrawActObj();
11276
11631
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
11277
- var zoomFactor = this.zoomFactor;
11278
11632
  this.drawRotatedImage(degree);
11279
11633
  this.clearOuterCanvas(this.lowerContext);
11280
11634
  this.clearOuterCanvas(this.upperContext);
@@ -11287,8 +11641,8 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11287
11641
  this.refreshToolbar('main', true, true);
11288
11642
  }
11289
11643
  }
11290
- if (!this.isUndoRedo) {
11291
- this.updateUndoRedoColl('rotate', degree, this.objColl, null, zoomFactor, this.adjustmentLevel.sharpen, this.adjustmentLevel.bw);
11644
+ if (!this.isUndoRedo && isNullOrUndefined(this.transformCurrentObj)) {
11645
+ this.updateUndoRedoColl('rotate', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
11292
11646
  }
11293
11647
  this.isUndoRedo = false;
11294
11648
  if (isNullOrUndefined(this.activeObj.shape) && !this.isReverseRotate) {
@@ -11297,7 +11651,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11297
11651
  else if (!this.isReverseRotate) {
11298
11652
  this.refreshToolbar('main', true, true);
11299
11653
  }
11300
- this.alignRotateFlipColl();
11654
+ this.rotateFlipColl = this.alignRotateFlipColl(this.rotateFlipColl, true);
11301
11655
  }
11302
11656
  return isRotate;
11303
11657
  };
@@ -11394,6 +11748,11 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11394
11748
  else if (splitWords !== undefined && splitWords[0] === 'crop') {
11395
11749
  isPrevent = true;
11396
11750
  }
11751
+ var prevCropObj = extend({}, this.cropObj, {}, true);
11752
+ var prevObj = this.getCurrentObj();
11753
+ prevObj.objColl = extend([], this.objColl, [], true);
11754
+ prevObj.pointColl = extend([], this.pointColl, [], true);
11755
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
11397
11756
  this.redrawActObj();
11398
11757
  this.refreshActiveObj();
11399
11758
  this.keyHistory = '';
@@ -11405,19 +11764,26 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11405
11764
  if (this.defaultZoomFactor > 0) {
11406
11765
  var zoomFactor = this.zoomFactor = this.defaultZoomFactor;
11407
11766
  this.isCropTab = false;
11767
+ var isUndoRedo = this.isUndoRedo;
11408
11768
  for (var i = 0; i < (zoomFactor * 10); i++) {
11769
+ this.isUndoRedo = true;
11409
11770
  this.zoom(-0.1);
11410
11771
  }
11772
+ this.isUndoRedo = isUndoRedo;
11411
11773
  this.resetPanPoints();
11412
11774
  }
11413
11775
  this.cancelObjColl = extend([], this.objColl, [], true);
11414
11776
  this.cancelPointColl = extend([], this.pointColl, [], true);
11777
+ this.updateObjAndFreeHandDrawColl();
11415
11778
  this.isCropTab = true;
11416
11779
  this.setCurrSelectionPoints(true);
11417
11780
  this.zoomFactor = this.cropZoomFactor;
11418
11781
  if (isNullOrUndefined(this.cropObj.activeObj.shape)) {
11419
11782
  this.drawNewSelection(type, startX, startY, width, height);
11420
11783
  }
11784
+ else {
11785
+ this.updateUndoRedoColl('crop-selection', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
11786
+ }
11421
11787
  }
11422
11788
  else {
11423
11789
  if (type === 'custom') {
@@ -11492,23 +11858,6 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11492
11858
  }
11493
11859
  }
11494
11860
  };
11495
- ImageEditor.prototype.setDestPointsForFlipState = function (isUpdate) {
11496
- if (this.getCurrentPanRegion() !== '') {
11497
- if (this.getCurrentPanRegion() === 'horizontal') {
11498
- this.destLeft = this.lowerCanvas.clientWidth - (this.destWidth + this.destLeft);
11499
- }
11500
- else if (this.getCurrentPanRegion() === 'vertical') {
11501
- this.destTop = this.lowerCanvas.clientHeight - (this.destHeight + this.destTop);
11502
- }
11503
- else {
11504
- this.destLeft = this.lowerCanvas.clientWidth - (this.destWidth + this.destLeft);
11505
- this.destTop = this.lowerCanvas.clientHeight - (this.destHeight + this.destTop);
11506
- }
11507
- if (!isNullOrUndefined(isUpdate)) {
11508
- this.updateObjAndFreeHandDrawColl();
11509
- }
11510
- }
11511
- };
11512
11861
  /**
11513
11862
  * Increase / Decrease the magnification of an image.
11514
11863
  *
@@ -11517,7 +11866,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11517
11866
  */
11518
11867
  ImageEditor.prototype.zoom = function (value) {
11519
11868
  if (!this.disabled && this.isImageLoaded) {
11520
- if ((this.zoomFactor === 0 && value < 0) || (this.zoomFactor > 5 && value > 0 ||
11869
+ if ((this.zoomFactor === 0 && value < 0) || (this.zoomFactor > 2 && value > 0 ||
11521
11870
  (this.zoomFactor > 0 && value < 0 && this.disableZoomOutBtn()))) {
11522
11871
  return;
11523
11872
  }
@@ -11534,29 +11883,37 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11534
11883
  else if (!isNullOrUndefined(this.activeObj.shape) && splitWords[0] !== 'crop') {
11535
11884
  isShape = true;
11536
11885
  }
11886
+ var zoomPoint = void 0;
11887
+ var zoomLevel = void 0;
11888
+ if (this.isCropTab && !isNullOrUndefined(tempActiveObj)) {
11889
+ zoomLevel = this.cropZoomFactor;
11890
+ zoomPoint = { x: this.activeObj.activePoint.startX + (this.activeObj.activePoint.width / 2),
11891
+ y: this.activeObj.activePoint.startY + (this.activeObj.activePoint.height / 2) };
11892
+ }
11893
+ else {
11894
+ zoomLevel = this.defaultZoomFactor;
11895
+ zoomPoint = { x: this.lowerCanvas.clientWidth / 2, y: this.lowerCanvas.clientHeight / 2 };
11896
+ }
11897
+ var zoomEventArgs = { zoomPoint: zoomPoint, zoomLevel: zoomLevel };
11898
+ this.trigger('zooming', zoomEventArgs);
11899
+ var prevCropObj = extend({}, this.cropObj, {}, true);
11900
+ var prevObj = this.getCurrentObj();
11901
+ prevObj.objColl = extend([], this.objColl, [], true);
11902
+ prevObj.pointColl = extend([], this.pointColl, [], true);
11903
+ prevObj.afterCropActions = extend([], this.afterCropActions, [], true);
11537
11904
  this.redrawActObj();
11538
11905
  this.refreshActiveObj();
11539
11906
  this.upperContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
11540
11907
  this.lowerContext.filter = this.canvasFilter;
11541
11908
  this.upperCanvas.style.cursor = 'default';
11542
- var zoomState = void 0;
11543
11909
  var objColl = extend([], this.objColl, [], true);
11544
- if (value === 3.75 || value === 1) {
11545
- zoomState = 0.1;
11546
- }
11547
- else if (value === -3.75) {
11548
- zoomState = -0.1;
11549
- }
11550
- else {
11551
- zoomState = value;
11552
- }
11553
11910
  if (!this.isCropTab) {
11554
11911
  if (this.degree !== 0) {
11555
11912
  this.redrawActObj();
11556
11913
  this.currentPannedPoint = { x: 0, y: 0 };
11557
- this.rotatePan();
11914
+ this.rotatePan(true, true);
11558
11915
  }
11559
- this.setDestPointsForFlipState(true);
11916
+ this.updateObjAndFreeHandDrawColl();
11560
11917
  }
11561
11918
  if (this.degree === 0) {
11562
11919
  this.drawZoomImgToCanvas(value, tempActiveObj);
@@ -11565,13 +11922,19 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11565
11922
  this.tempFlipPanPoint.y += this.totalPannedPoint.y;
11566
11923
  objColl = extend([], this.objColl, [], true);
11567
11924
  this.objColl = [];
11925
+ var destLeft = this.destLeft;
11926
+ var destTop = this.destTop;
11927
+ this.setDestPointsForFlipState();
11568
11928
  this.rotatedFlip();
11569
- if (this.totalPannedPoint.x !== 0 || this.totalPannedPoint.y !== 0) {
11570
- this.totalPannedPoint = { x: 0, y: 0 };
11571
- }
11572
- if (this.tempPannedPoint.x !== 0 || this.tempPannedPoint.y !== 0) {
11573
- this.tempPannedPoint = { x: 0, y: 0 };
11574
- }
11929
+ this.destLeft = destLeft;
11930
+ this.destTop = destTop;
11931
+ this.objColl = objColl;
11932
+ this.zoomObjColl();
11933
+ this.zoomFreehandDrawColl();
11934
+ this.updateObjAndFreeHandDrawColl();
11935
+ }
11936
+ if (this.zoomFactor === 0 && !this.isCropTab) {
11937
+ this.totalPannedPoint = { x: 0, y: 0 };
11575
11938
  }
11576
11939
  }
11577
11940
  else {
@@ -11594,19 +11957,6 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11594
11957
  this.zoomFreehandDrawColl();
11595
11958
  this.lowerContext.filter = temp;
11596
11959
  }
11597
- else if (this.degree === 0) {
11598
- var temp = this.lowerContext.filter;
11599
- this.lowerContext.filter = 'none';
11600
- var destLeft = this.destLeft;
11601
- var destTop = this.destTop;
11602
- this.setDestPointsForFlipState();
11603
- this.objColl = objColl;
11604
- this.zoomObjColl();
11605
- this.zoomFreehandDrawColl();
11606
- this.destLeft = destLeft;
11607
- this.destTop = destTop;
11608
- this.lowerContext.filter = temp;
11609
- }
11610
11960
  if ((!isNullOrUndefined(this.currSelectionPoint) && this.currSelectionPoint.shape === 'crop-circle') || this.isCircleCrop) {
11611
11961
  this.cropCircle(this.lowerContext);
11612
11962
  }
@@ -11615,18 +11965,12 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11615
11965
  if (!isNullOrUndefined(tempActiveObj)) {
11616
11966
  this.activeObj = extend({}, tempActiveObj, {}, true);
11617
11967
  this.drawObject('duplicate', this.activeObj);
11618
- if (this.currentToolbar === 'crop') {
11619
- this.refreshToolbar('main', true, true);
11620
- }
11621
- else {
11622
- this.refreshToolbar(this.currentToolbar, true, true);
11623
- }
11624
11968
  if (this.zoomFactor === 0) {
11625
11969
  this.currSelectionPoint = null;
11626
11970
  }
11627
11971
  }
11628
11972
  if (!this.isUndoRedo) {
11629
- this.updateUndoRedoColl('zoom', zoomState, this.objColl, null, this.zoomFactor, this.adjustmentLevel.sharpen, this.adjustmentLevel.bw);
11973
+ this.updateUndoRedoColl('zoom', prevObj, prevObj.objColl, prevObj.pointColl, prevCropObj);
11630
11974
  }
11631
11975
  this.isUndoRedo = false;
11632
11976
  var zoomOut = document.querySelector('#' + this.element.id + '_zoomOut');
@@ -11638,9 +11982,6 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11638
11982
  zoomOut.classList.remove('e-disabled');
11639
11983
  zoomOut.parentElement.classList.remove('e-overlay');
11640
11984
  }
11641
- if (!this.togglePan) {
11642
- this.callMainToolbar(false, true);
11643
- }
11644
11985
  this.autoEnablePan();
11645
11986
  if (!isNullOrUndefined(tempActiveObj)) {
11646
11987
  this.activeObj = extend({}, tempActiveObj, {}, true);
@@ -11648,24 +11989,6 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11648
11989
  if (this.activeObj.shape === 'crop-custom') {
11649
11990
  this.currObjType.isCustomCrop = true;
11650
11991
  }
11651
- if (isNullOrUndefined(this.activeObj.activePoint) || this.activeObj.activePoint.width === 0) {
11652
- if (this.currentToolbar === 'crop' || !isNullOrUndefined(tempActiveObj)) {
11653
- this.refreshToolbar('main', true, true);
11654
- }
11655
- else {
11656
- this.refreshToolbar('main');
11657
- this.currentToolbar = 'main';
11658
- }
11659
- }
11660
- else {
11661
- if (this.currentToolbar === 'crop' || !isNullOrUndefined(tempActiveObj)) {
11662
- this.refreshToolbar('main', true, true);
11663
- }
11664
- else {
11665
- this.refreshToolbar('main');
11666
- this.currentToolbar = 'main';
11667
- }
11668
- }
11669
11992
  var panBtn = this.element.querySelector('.e-img-pan .e-btn');
11670
11993
  if (!isNullOrUndefined(panBtn) && this.togglePan) {
11671
11994
  panBtn.classList.add('e-selected-btn');
@@ -11677,12 +12000,6 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
11677
12000
  this.activeObj = extend({}, this.objColl[this.objColl.length - 1], {}, true);
11678
12001
  this.objColl.pop();
11679
12002
  this.drawObject('duplicate', this.activeObj);
11680
- if (this.activeObj.shape === 'text') {
11681
- this.refreshToolbar('text');
11682
- }
11683
- else {
11684
- this.refreshToolbar('shapes');
11685
- }
11686
12003
  this.updateToolbarItems();
11687
12004
  }
11688
12005
  }
@@ -12086,14 +12403,13 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
12086
12403
  else {
12087
12404
  this.refreshToolbar('main');
12088
12405
  }
12089
- if (this.activeObj.activePoint.width !== 0) {
12406
+ if (!isNullOrUndefined(this.activeObj.activePoint) && this.activeObj.activePoint.width !== 0) {
12090
12407
  this.tempActObj = this.activeObj;
12091
12408
  }
12092
- //this.refreshActiveObj();
12409
+ this.refreshActiveObj();
12093
12410
  this.undoRedoStep--;
12094
12411
  this.enableDisableToolbarBtn();
12095
12412
  this.isUndoRedo = true;
12096
- this.lowerContext.filter = this.canvasFilter;
12097
12413
  var obj = this.undoRedoColl[this.undoRedoStep];
12098
12414
  if (this.undoRedoColl.length === this.undoRedoStep) {
12099
12415
  this.currObjType.isUndoAction = false;
@@ -12101,82 +12417,47 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
12101
12417
  else {
12102
12418
  this.currObjType.isUndoAction = true;
12103
12419
  }
12104
- if (obj.operation !== 'textTransform' && this.textArea.style.display === 'block') {
12420
+ if (obj.operation !== 'textAreaCustomization' && this.textArea.style.display === 'block') {
12105
12421
  this.textArea.style.display = 'none';
12106
12422
  }
12107
12423
  this.element.querySelector('.e-contextual-toolbar-wrapper').classList.add('e-hide');
12108
- var xDiff = void 0;
12109
- var yDiff = void 0;
12110
- var tempUndoRedoColl = [];
12111
- var prevObj = void 0;
12112
- var value = '';
12424
+ this.isCancelAction = true;
12425
+ var activeObj = void 0;
12426
+ this.cropObj = extend({}, obj.previousCropObj, {}, true);
12427
+ this.afterCropActions = obj.previousObj.afterCropActions;
12428
+ this.lowerContext.filter = this.canvasFilter = obj.previousObj.filter;
12113
12429
  switch (obj.operation) {
12114
- case 'rotate':
12115
- if (obj.value === 90) {
12116
- value = 'rotateleft';
12117
- }
12118
- else if (obj.value === -90) {
12119
- value = 'rotateright';
12120
- }
12121
- this.performTransformation(value);
12122
- break;
12123
- case 'flip':
12124
- if (obj.value.toLowerCase() === 'horizontal') {
12125
- value = 'horizontalflip';
12126
- }
12127
- else if (obj.value.toLowerCase() === 'vertical') {
12128
- value = 'verticalflip';
12129
- }
12130
- this.performTransformation(value);
12131
- break;
12132
- case 'zoom':
12133
- if (this.zoomFactor === 0 && obj.zoomFactor !== 0) {
12134
- this.zoomFactor = obj.zoomFactor;
12135
- }
12136
- this.zoom(-obj.value);
12430
+ case 'shapeTransform':
12431
+ this.objColl = extend([], obj.previousObjColl, [], true);
12432
+ this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
12433
+ this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
12137
12434
  this.isUndoRedo = true;
12138
- break;
12139
- case 'pan':
12140
- xDiff = this.destLeft;
12141
- yDiff = this.destTop;
12142
- this.destLeft = obj.previousObj.x;
12143
- this.destTop = obj.previousObj.y;
12144
- xDiff += this.destLeft;
12145
- yDiff += this.destTop;
12146
- this.drawPannedImage(xDiff, yDiff);
12147
- break;
12148
- case 'crop':
12149
- if (!isNullOrUndefined(this.currSelectionPoint)) {
12150
- tempUndoRedoColl = extend([], this.undoRedoColl, [], true);
12151
- this.select('Custom');
12152
- this.refreshToolbar('main', true, true);
12153
- getComponent(this.element.querySelector('#' + this.element.id + '_cropBtn'), 'dropdown-btn').toggle();
12154
- this.undoRedoColl = tempUndoRedoColl;
12155
- this.enableDisableToolbarBtn();
12156
- }
12435
+ this.redrawImgWithObj();
12436
+ this.refreshActiveObj();
12157
12437
  break;
12158
12438
  case 'freehanddraw':
12159
- this.pointColl = obj.previousObj;
12160
- this.freehandCounter--;
12439
+ this.pointColl = obj.previousPointColl;
12440
+ this.freehandCounter = this.pointColl.length;
12161
12441
  this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
12162
12442
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
12163
12443
  this.isUndoRedo = true;
12164
12444
  this.redrawImgWithObj();
12165
12445
  break;
12166
12446
  case 'freehanddrawCustomized':
12167
- this.pointColl = obj.previousObj;
12447
+ this.pointColl = obj.previousPointColl;
12168
12448
  this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
12169
12449
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
12170
12450
  this.isUndoRedo = true;
12171
12451
  this.redrawImgWithObj();
12172
12452
  break;
12173
- case 'delete':
12174
- if (obj.value === 'freehanddraw') {
12175
- this.pointColl = obj.previousObj;
12176
- this.freehandCounter++;
12453
+ case 'deleteFreehandDrawing':
12454
+ case 'deleteObj':
12455
+ if (obj.operation === 'deleteFreehandDrawing') {
12456
+ this.pointColl = obj.previousPointColl;
12457
+ this.freehandCounter = this.pointColl.length;
12177
12458
  }
12178
- else if (obj.value === 'shape') {
12179
- this.objColl = obj.previousObj;
12459
+ else if (obj.operation === 'deleteObj') {
12460
+ this.objColl = obj.previousObjColl;
12180
12461
  }
12181
12462
  this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
12182
12463
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
@@ -12184,7 +12465,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
12184
12465
  this.redrawImgWithObj();
12185
12466
  break;
12186
12467
  case 'selectionTransform':
12187
- this.activeObj = extend({}, obj.previousSelectionObj, {}, true);
12468
+ this.activeObj = extend({}, obj.previousObj.activeObj, {}, true);
12188
12469
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
12189
12470
  if (this.activeObj.activePoint.width !== 0 && this.activeObj.activePoint.height !== 0) {
12190
12471
  this.drawObject('duplicate', this.activeObj);
@@ -12192,83 +12473,84 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
12192
12473
  }
12193
12474
  else {
12194
12475
  this.refreshToolbar('main');
12476
+ this.performUndoDefaultAction(obj);
12195
12477
  }
12196
12478
  this.currObjType.isCustomCrop = false;
12197
12479
  break;
12198
- case 'shapeTransform':
12199
- this.objColl = extend([], obj.previousObj, [], true);
12200
- this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
12201
- this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
12202
- this.isUndoRedo = true;
12203
- this.redrawImgWithObj();
12204
- this.refreshActiveObj();
12205
- break;
12206
- case 'textTransform':
12207
- this.objColl = extend([], obj.previousObj, [], true);
12208
- for (var i = 0; i < obj.previousObj.length; i++) {
12209
- if (this.tempActObj.currIndex === obj.previousObj[i].currIndex) {
12210
- prevObj = extend({}, obj.previousObj[i], {}, true);
12480
+ case 'textAreaCustomization':
12481
+ this.objColl = extend([], obj.previousObjColl, [], true);
12482
+ for (var i = 0; i < obj.previousObjColl.length; i++) {
12483
+ if (!isNullOrUndefined(this.tempActObj)) {
12484
+ if (this.tempActObj.currIndex === obj.previousObjColl[i].currIndex) {
12485
+ activeObj = extend({}, obj.previousObjColl[i], {}, true);
12486
+ this.objColl.splice(i, 1);
12487
+ break;
12488
+ }
12489
+ }
12490
+ else {
12491
+ activeObj = extend({}, obj.previousObjColl[obj.previousObjColl.length - 1], {}, true);
12211
12492
  this.objColl.splice(i, 1);
12212
12493
  break;
12213
12494
  }
12214
12495
  }
12215
- if (!isNullOrUndefined(prevObj)) {
12216
- this.updateTextBox(prevObj);
12496
+ if (!isNullOrUndefined(activeObj)) {
12497
+ this.updateTextBox(activeObj);
12217
12498
  }
12218
12499
  break;
12219
12500
  case 'text':
12220
12501
  if (!isNullOrUndefined(this.tempActObj)) {
12221
12502
  this.activeObj = extend({}, this.tempActObj, {}, true);
12222
12503
  }
12223
- if (obj.value.length === 0 && this.objColl.length === 1) {
12504
+ if (obj.previousObjColl.length === 0 && this.objColl.length === 1) {
12224
12505
  this.tempActObj = extend({}, this.objColl[0], {}, true);
12225
12506
  }
12226
12507
  else {
12227
12508
  for (var i = 0; i < this.objColl.length; i++) {
12228
12509
  if (!isNullOrUndefined(this.objColl[i]) &&
12229
- isNullOrUndefined(obj.value[i])) {
12230
- this.tempActObj = extend({}, obj.value[i], {}, true);
12510
+ isNullOrUndefined(obj.previousObjColl[i])) {
12511
+ this.tempActObj = extend({}, this.objColl[i], {}, true);
12231
12512
  break;
12232
12513
  }
12233
- if (obj.value[i].currIndex !== this.objColl[i].currIndex) {
12514
+ if (obj.previousObjColl[i].currIndex !== this.objColl[i].currIndex) {
12234
12515
  this.tempActObj = extend({}, this.objColl[i], {}, true);
12235
12516
  break;
12236
12517
  }
12237
12518
  }
12238
12519
  }
12239
12520
  this.activeObj = extend({}, this.tempActObj, {}, true);
12240
- this.objColl = extend([], obj.value, [], true);
12521
+ this.objColl = extend([], obj.previousObjColl, [], true);
12241
12522
  this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
12242
12523
  this.isUndoRedo = true;
12243
12524
  this.redrawImgWithObj();
12244
- this.textArea.style.display = 'block';
12245
- this.textArea.value = obj.previousObj;
12246
- break;
12247
- case 'brightness':
12248
- case 'contrast':
12249
- case 'hue':
12250
- case 'saturation':
12251
- case 'opacity':
12252
- case 'blur':
12253
- case 'exposure':
12254
- this.lowerContext.filter = this.canvasFilter = obj.previousObj;
12255
- if (this.lowerContext.filter.split(' ').length > 1 &&
12256
- this.lowerContext.filter.split(' ')[0].split('(')[1].split(')')[0] === '1') {
12257
- this.isBrightnessAdjusted = false;
12525
+ if (!isNullOrUndefined(this.activeObj) && this.activeObj.activePoint.width !== 0
12526
+ && this.activeObj.activePoint.height !== 0) {
12527
+ this.drawObject('duplicate');
12528
+ }
12529
+ else {
12530
+ this.textArea.style.display = 'block';
12531
+ this.textArea.value = obj.previousText;
12258
12532
  }
12259
- this.setAdjustment(obj.operation);
12260
- this.isUndoRedo = true;
12261
12533
  break;
12262
- case 'default':
12263
- case 'chrome':
12264
- case 'cold':
12265
- case 'warm':
12266
- case 'grayscale':
12267
- case 'sepia':
12268
- case 'invert':
12269
- this.updateFilter(obj);
12534
+ default:
12535
+ this.performUndoDefaultAction(obj);
12536
+ this.setAdjustment(obj.operation);
12537
+ this.updateFilter(obj.operation, obj.filter);
12270
12538
  break;
12271
12539
  }
12540
+ this.clearOuterCanvas(this.lowerContext);
12541
+ if (this.isCircleCrop && obj.operation !== 'crop') {
12542
+ this.cropCircle(this.lowerContext);
12543
+ }
12544
+ if (this.zoomFactor > 0) {
12545
+ this.dragCanvas = true;
12546
+ }
12547
+ this.isCancelAction = false;
12548
+ if (!isNullOrUndefined(this.activeObj.shape) && this.activeObj.shape.split('-')[0] === 'crop') {
12549
+ this.refreshToolbar('main', true, true);
12550
+ }
12551
+ else {
12552
+ this.refreshToolbar('main');
12553
+ }
12272
12554
  }
12273
12555
  }
12274
12556
  };
@@ -12290,7 +12572,6 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
12290
12572
  this.undoRedoStep++;
12291
12573
  this.enableDisableToolbarBtn();
12292
12574
  this.isUndoRedo = true;
12293
- this.lowerContext.filter = this.canvasFilter;
12294
12575
  var obj = this.undoRedoColl[this.undoRedoStep - 1];
12295
12576
  if (this.undoRedoColl.length === this.undoRedoStep) {
12296
12577
  this.currObjType.isUndoAction = false;
@@ -12298,74 +12579,49 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
12298
12579
  else {
12299
12580
  this.currObjType.isUndoAction = true;
12300
12581
  }
12301
- if (obj.operation !== 'textTransform' && this.textArea.style.display === 'block') {
12582
+ if (obj.operation !== 'textAreaCustomization' && this.textArea.style.display === 'block') {
12302
12583
  this.textArea.style.display = 'none';
12303
12584
  }
12304
12585
  this.element.querySelector('.e-contextual-toolbar-wrapper').classList.add('e-hide');
12305
- var selEle = this.element.querySelector('.e-contextual-toolbar-wrapper .e-toolbar-item.e-selected');
12306
- var xDiff = void 0;
12307
- var yDiff = void 0;
12586
+ this.isCancelAction = true;
12587
+ this.cropObj = extend({}, obj.currentCropObj, {}, true);
12588
+ this.afterCropActions = obj.currentObj.afterCropActions;
12589
+ this.lowerContext.filter = this.canvasFilter = obj.currentObj.filter;
12590
+ var activeObj = void 0;
12308
12591
  var tempUndoRedoColl = void 0;
12309
12592
  var tempUndoRedoStep = void 0;
12310
- var value = '';
12311
- var currObj = void 0;
12312
12593
  switch (obj.operation) {
12313
- case 'rotate':
12314
- if (obj.value === 90) {
12315
- value = 'rotateright';
12316
- }
12317
- else if (obj.value === -90) {
12318
- value = 'rotateleft';
12319
- }
12320
- this.performTransformation(value);
12321
- break;
12322
- case 'flip':
12323
- if (obj.value.toLowerCase() === 'horizontal') {
12324
- value = 'horizontalflip';
12325
- }
12326
- else if (obj.value.toLowerCase() === 'vertical') {
12327
- value = 'verticalflip';
12328
- }
12329
- this.performTransformation(value);
12330
- break;
12331
- case 'zoom':
12332
- this.zoom(obj.value);
12333
- break;
12334
- case 'pan':
12335
- xDiff = this.destLeft;
12336
- yDiff = this.destTop;
12337
- this.destLeft = obj.currentObj.x;
12338
- this.destTop = obj.currentObj.y;
12339
- xDiff += this.destLeft;
12340
- yDiff += this.destTop;
12341
- this.drawPannedImage(xDiff, yDiff);
12342
- break;
12343
- case 'crop':
12344
- this.cropImg();
12345
- this.refreshToolbar('main');
12594
+ case 'shapeTransform':
12595
+ this.objColl = extend([], obj.currentObjColl, [], true);
12596
+ this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
12597
+ this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
12598
+ this.isUndoRedo = true;
12599
+ this.redrawImgWithObj();
12600
+ this.refreshActiveObj();
12346
12601
  break;
12347
12602
  case 'freehanddraw':
12348
- this.pointColl = obj.currentObj;
12349
- this.freehandCounter++;
12603
+ this.pointColl = obj.currentPointColl;
12604
+ this.freehandCounter = this.pointColl.length;
12350
12605
  this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
12351
12606
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
12352
12607
  this.isUndoRedo = true;
12353
12608
  this.redrawImgWithObj();
12354
12609
  break;
12355
12610
  case 'freehanddrawCustomized':
12356
- this.pointColl = obj.currentObj;
12611
+ this.pointColl = obj.currentPointColl;
12357
12612
  this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
12358
12613
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
12359
12614
  this.isUndoRedo = true;
12360
12615
  this.redrawImgWithObj();
12361
12616
  break;
12362
- case 'delete':
12363
- if (obj.value === 'freehanddraw') {
12364
- this.pointColl = obj.currentObj;
12365
- this.freehandCounter--;
12617
+ case 'deleteFreehandDrawing':
12618
+ case 'deleteObj':
12619
+ if (obj.operation === 'deleteFreehandDrawing') {
12620
+ this.pointColl = obj.currentPointColl;
12621
+ this.freehandCounter = this.pointColl.length;
12366
12622
  }
12367
- else if (obj.value === 'shape') {
12368
- this.objColl = obj.currentObj;
12623
+ else if (obj.operation === 'deleteObj') {
12624
+ this.objColl = obj.currentObjColl;
12369
12625
  }
12370
12626
  this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
12371
12627
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
@@ -12373,15 +12629,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
12373
12629
  this.redrawImgWithObj();
12374
12630
  break;
12375
12631
  case 'selectionTransform':
12376
- if (this.zoomFactor !== obj.zoomFactor) {
12377
- if (this.zoomFactor > 0) {
12378
- this.zoom(-this.zoomFactor);
12379
- }
12380
- else {
12381
- this.zoom(Math.abs(this.zoomFactor));
12382
- }
12383
- }
12384
- this.activeObj = extend({}, obj.currentSelectionObj, {}, true);
12632
+ this.activeObj = extend({}, obj.currentObj.activeObj, {}, true);
12385
12633
  this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
12386
12634
  if (this.activeObj.activePoint.width !== 0 && this.activeObj.activePoint.height !== 0) {
12387
12635
  this.drawObject('duplicate', this.activeObj);
@@ -12390,38 +12638,57 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
12390
12638
  else {
12391
12639
  this.refreshToolbar('main');
12392
12640
  }
12641
+ this.currObjType.isCustomCrop = false;
12393
12642
  break;
12394
- case 'shapeTransform':
12395
- this.objColl = extend([], obj.currentObj, [], true);
12396
- this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
12397
- this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
12398
- this.isUndoRedo = true;
12399
- this.redrawImgWithObj();
12400
- this.refreshActiveObj();
12401
- break;
12402
- case 'textTransform':
12403
- this.objColl = extend([], obj.currentObj, [], true);
12404
- for (var i = 0; i < obj.previousObj.length; i++) {
12405
- if (this.tempActObj.currIndex === obj.currentObj[i].currIndex) {
12406
- currObj = extend({}, obj.currentObj[i], {}, true);
12643
+ case 'textAreaCustomization':
12644
+ this.objColl = extend([], obj.currentObjColl, [], true);
12645
+ for (var i = 0; i < obj.currentObjColl.length; i++) {
12646
+ if (!isNullOrUndefined(this.tempActObj)) {
12647
+ if (this.tempActObj.currIndex === obj.currentObjColl[i].currIndex) {
12648
+ activeObj = extend({}, obj.currentObjColl[i], {}, true);
12649
+ this.objColl.splice(i, 1);
12650
+ break;
12651
+ }
12652
+ }
12653
+ else {
12654
+ activeObj = extend({}, obj.currentObjColl[obj.currentObjColl.length - 1], {}, true);
12407
12655
  this.objColl.splice(i, 1);
12408
12656
  break;
12409
12657
  }
12410
12658
  }
12411
- if (!isNullOrUndefined(currObj)) {
12412
- this.updateTextBox(currObj);
12659
+ if (!isNullOrUndefined(activeObj)) {
12660
+ this.updateTextBox(activeObj);
12413
12661
  }
12414
12662
  break;
12415
12663
  case 'text':
12416
12664
  if (!isNullOrUndefined(this.tempActObj)) {
12417
12665
  this.activeObj = extend({}, this.tempActObj, {}, true);
12418
12666
  }
12419
- this.objColl = extend([], obj.value, [], true);
12667
+ if (obj.previousObjColl.length === 0 && this.objColl.length === 1) {
12668
+ this.tempActObj = extend({}, this.objColl[0], {}, true);
12669
+ }
12670
+ else {
12671
+ for (var i = 0; i < this.objColl.length; i++) {
12672
+ if (!isNullOrUndefined(this.objColl[i]) &&
12673
+ isNullOrUndefined(obj.previousObjColl[i])) {
12674
+ this.tempActObj = extend({}, this.objColl[i], {}, true);
12675
+ break;
12676
+ }
12677
+ if (obj.previousObjColl[i].currIndex !== this.objColl[i].currIndex) {
12678
+ this.tempActObj = extend({}, this.objColl[i], {}, true);
12679
+ break;
12680
+ }
12681
+ }
12682
+ }
12683
+ this.objColl = extend([], obj.currentObjColl, [], true);
12420
12684
  this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
12421
12685
  this.isUndoRedo = true;
12422
12686
  this.redrawImgWithObj();
12687
+ if (!isNullOrUndefined(this.tempActObj)) {
12688
+ this.activeObj = extend({}, this.tempActObj, {}, true);
12689
+ }
12423
12690
  this.textArea.style.display = 'block';
12424
- this.textArea.value = obj.currentObj;
12691
+ this.textArea.value = obj.currentText;
12425
12692
  tempUndoRedoColl = extend([], this.undoRedoColl, [], true);
12426
12693
  tempUndoRedoStep = this.undoRedoStep;
12427
12694
  this.redrawActObj();
@@ -12429,39 +12696,49 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
12429
12696
  this.undoRedoStep = tempUndoRedoStep;
12430
12697
  this.textArea.style.display = 'none';
12431
12698
  this.textArea.value = '';
12699
+ this.redrawActObj();
12432
12700
  break;
12433
- case 'brightness':
12434
- case 'contrast':
12435
- case 'hue':
12436
- case 'saturation':
12437
- case 'opacity':
12438
- case 'blur':
12439
- case 'exposure':
12440
- this.lowerContext.filter = this.canvasFilter = obj.currentObj;
12441
- this.setAdjustment(obj.operation);
12442
- break;
12443
- case 'default':
12444
- case 'chrome':
12445
- case 'cold':
12446
- case 'warm':
12447
- case 'grayscale':
12448
- case 'sepia':
12449
- case 'invert':
12450
- if (selEle) {
12451
- selEle.classList.remove('e-selected');
12452
- }
12453
- if (document.getElementById(this.element.id + '_' + obj.operation + 'Canvas')) {
12454
- document.getElementById(this.element.id + '_' + obj.operation + 'Canvas').parentElement.classList.add('e-selected');
12701
+ default:
12702
+ this.objColl = [];
12703
+ this.pointColl = [];
12704
+ this.freehandCounter = 0;
12705
+ this.setCurrentObj(obj.currentObj);
12706
+ this.destLeft = obj.currentObj.destPoints.startX;
12707
+ this.destTop = obj.currentObj.destPoints.startY;
12708
+ activeObj = extend({}, this.activeObj, {}, true);
12709
+ this.objColl = extend([], obj.currentObjColl, [], true);
12710
+ this.pointColl = extend([], obj.currentPointColl, [], true);
12711
+ this.freehandCounter = this.pointColl.length;
12712
+ this.lowerContext.filter = 'none';
12713
+ this.iterateObjColl();
12714
+ this.freehandRedraw(this.lowerContext);
12715
+ this.lowerContext.filter = obj.currentObj.filter;
12716
+ this.activeObj = activeObj;
12717
+ this.upperContext.clearRect(0, 0, this.upperCanvas.width, this.upperCanvas.height);
12718
+ if (this.activeObj.activePoint.width !== 0 && this.activeObj.activePoint.height !== 0) {
12719
+ this.drawObject('duplicate');
12455
12720
  }
12456
- this.currentFilter = this.element.id + '_' + obj.operation;
12457
- this.lowerContext.filter = this.canvasFilter = obj.currentObj;
12458
- this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
12459
- this.redrawImgWithObj();
12721
+ this.setAdjustment(obj.operation);
12722
+ this.updateFilter(obj.operation);
12460
12723
  break;
12461
12724
  }
12725
+ this.clearOuterCanvas(this.lowerContext);
12726
+ if (this.isCircleCrop) {
12727
+ this.cropCircle(this.lowerContext);
12728
+ }
12729
+ if (this.zoomFactor > 0) {
12730
+ this.dragCanvas = true;
12731
+ }
12732
+ this.isCancelAction = false;
12462
12733
  if (this.undoRedoStep === this.undoRedoColl.length) {
12463
12734
  this.isUndoRedo = false;
12464
12735
  }
12736
+ if (!isNullOrUndefined(this.activeObj.shape) && this.activeObj.shape.split('-')[0] === 'crop') {
12737
+ this.refreshToolbar('main', true, true);
12738
+ }
12739
+ else {
12740
+ this.refreshToolbar('main');
12741
+ }
12465
12742
  }
12466
12743
  }
12467
12744
  };