@syncfusion/ej2-image-editor 21.1.35 → 21.1.37

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.
@@ -222,6 +222,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
222
222
  _this.isShapeInserted = false;
223
223
  _this.isInitialTextEdited = false;
224
224
  _this.isShapeTextInserted = false;
225
+ _this.isErrorImage = false;
225
226
  return _this;
226
227
  }
227
228
  ImageEditor_1 = ImageEditor;
@@ -427,7 +428,8 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
427
428
  this.zoomSettings.zoomTrigger = newProperties.zoomSettings.zoomTrigger;
428
429
  }
429
430
  if (isNullOrUndefined(this.zoomSettings.zoomTrigger)) {
430
- this.zoomSettings.zoomTrigger = (ZoomTrigger.MouseWheel | ZoomTrigger.Pinch | ZoomTrigger.Toolbar | ZoomTrigger.Commands);
431
+ this.zoomSettings.zoomTrigger = (ZoomTrigger.MouseWheel | ZoomTrigger.Pinch | ZoomTrigger.Toolbar |
432
+ ZoomTrigger.Commands);
431
433
  this.refreshToolbar('main');
432
434
  }
433
435
  else if ((newProperties.zoomSettings.zoomTrigger & ZoomTrigger.Toolbar) === ZoomTrigger.Toolbar) {
@@ -1324,11 +1326,9 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1324
1326
  this.performTransformation(args.item.id);
1325
1327
  this.updateCurrentUndoRedoColl('ok');
1326
1328
  };
1327
- ImageEditor.prototype.performTransformation = function (text) {
1328
- var tempZoomFactor = this.defaultZoomFactor;
1329
- var isUndoRedo = this.isUndoRedo;
1330
- var prevCropObj = extend({}, this.cropObj, {}, true);
1329
+ ImageEditor.prototype.resetZoom = function () {
1331
1330
  if (this.defaultZoomFactor !== 0) {
1331
+ var isUndoRedo = this.isUndoRedo;
1332
1332
  this.transformCurrentObj = this.getCurrentObj();
1333
1333
  this.transformCurrentObj.objColl = extend([], this.objColl, null, true);
1334
1334
  this.transformCurrentObj.pointColl = extend({}, this.pointColl, null, true);
@@ -1342,6 +1342,12 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
1342
1342
  }
1343
1343
  this.isUndoRedo = isUndoRedo;
1344
1344
  }
1345
+ };
1346
+ ImageEditor.prototype.performTransformation = function (text) {
1347
+ var tempZoomFactor = this.defaultZoomFactor;
1348
+ var isUndoRedo = this.isUndoRedo;
1349
+ var prevCropObj = extend({}, this.cropObj, {}, true);
1350
+ this.resetZoom();
1345
1351
  this.updateTransform(text);
1346
1352
  if (tempZoomFactor !== 0) {
1347
1353
  this.isUndoRedo = true;
@@ -2325,7 +2331,6 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
2325
2331
  isDisabledFilter = true;
2326
2332
  }
2327
2333
  this.enableDisableToolbarBtn();
2328
- var previousObj = void 0;
2329
2334
  var duplicateObj = void 0;
2330
2335
  var objColl = void 0;
2331
2336
  if (!this.disabled) {
@@ -2375,11 +2380,6 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
2375
2380
  this.currentToolbar = 'main';
2376
2381
  break;
2377
2382
  case 'crop':
2378
- previousObj = this.getCurrentObj();
2379
- previousObj.objColl = extend([], this.objColl, [], true);
2380
- previousObj.pointColl = extend([], this.pointColl, [], true);
2381
- previousObj.afterCropActions = this.afterCropActions;
2382
- this.previousCropCurrentObj = previousObj;
2383
2383
  if (!isNullOrUndefined(this.currSelectionPoint)) {
2384
2384
  if (this.currObjType.isUndoAction) {
2385
2385
  this.refreshUndoRedoColl();
@@ -4445,48 +4445,63 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
4445
4445
  this.inMemoryCanvas.width = imageData.width;
4446
4446
  this.inMemoryCanvas.height = imageData.height;
4447
4447
  this.inMemoryContext.putImageData(imageData, 0, 0);
4448
+ var ctx;
4448
4449
  var noFilter = document.querySelector('#' + this.element.id + '_defaultCanvas');
4449
- var ctx = noFilter.getContext('2d');
4450
- noFilter.style.width = '100px';
4451
- noFilter.style.height = '100px';
4452
- ctx.filter = this.updateAdjustment('default', null, true);
4453
- ctx.drawImage(this.inMemoryCanvas, 0, 0, 300, 150);
4450
+ if (!isNullOrUndefined(noFilter)) {
4451
+ ctx = noFilter.getContext('2d');
4452
+ noFilter.style.width = '100px';
4453
+ noFilter.style.height = '100px';
4454
+ ctx.filter = this.updateAdjustment('default', null, true);
4455
+ ctx.drawImage(this.inMemoryCanvas, 0, 0, 300, 150);
4456
+ }
4454
4457
  var chrome = document.querySelector('#' + this.element.id + '_chromeCanvas');
4455
- ctx = chrome.getContext('2d');
4456
- chrome.style.width = '100px';
4457
- chrome.style.height = '100px';
4458
- ctx.filter = this.updateAdjustment('chrome', null, true);
4459
- ctx.drawImage(this.inMemoryCanvas, 0, 0, 300, 150);
4458
+ if (!isNullOrUndefined(chrome)) {
4459
+ ctx = chrome.getContext('2d');
4460
+ chrome.style.width = '100px';
4461
+ chrome.style.height = '100px';
4462
+ ctx.filter = this.updateAdjustment('chrome', null, true);
4463
+ ctx.drawImage(this.inMemoryCanvas, 0, 0, 300, 150);
4464
+ }
4460
4465
  var cold = document.querySelector('#' + this.element.id + '_coldCanvas');
4461
- ctx = cold.getContext('2d');
4462
- cold.style.width = '100px';
4463
- cold.style.height = '100px';
4464
- ctx.filter = this.updateAdjustment('cold', null, true);
4465
- ctx.drawImage(this.inMemoryCanvas, 0, 0, 300, 150);
4466
+ if (!isNullOrUndefined(cold)) {
4467
+ ctx = cold.getContext('2d');
4468
+ cold.style.width = '100px';
4469
+ cold.style.height = '100px';
4470
+ ctx.filter = this.updateAdjustment('cold', null, true);
4471
+ ctx.drawImage(this.inMemoryCanvas, 0, 0, 300, 150);
4472
+ }
4466
4473
  var warm = document.querySelector('#' + this.element.id + '_warmCanvas');
4467
- ctx = warm.getContext('2d');
4468
- warm.style.width = '100px';
4469
- warm.style.height = '100px';
4470
- ctx.filter = this.updateAdjustment('warm', null, true);
4471
- ctx.drawImage(this.inMemoryCanvas, 0, 0, 300, 150);
4474
+ if (!isNullOrUndefined(warm)) {
4475
+ ctx = warm.getContext('2d');
4476
+ warm.style.width = '100px';
4477
+ warm.style.height = '100px';
4478
+ ctx.filter = this.updateAdjustment('warm', null, true);
4479
+ ctx.drawImage(this.inMemoryCanvas, 0, 0, 300, 150);
4480
+ }
4472
4481
  var grayscale = document.querySelector('#' + this.element.id + '_grayscaleCanvas');
4473
- ctx = grayscale.getContext('2d');
4474
- grayscale.style.width = '100px';
4475
- grayscale.style.height = '100px';
4476
- ctx.filter = this.updateAdjustment('grayscale', null, true);
4477
- ctx.drawImage(this.inMemoryCanvas, 0, 0, 300, 150);
4482
+ if (!isNullOrUndefined(grayscale)) {
4483
+ ctx = grayscale.getContext('2d');
4484
+ grayscale.style.width = '100px';
4485
+ grayscale.style.height = '100px';
4486
+ ctx.filter = this.updateAdjustment('grayscale', null, true);
4487
+ ctx.drawImage(this.inMemoryCanvas, 0, 0, 300, 150);
4488
+ }
4478
4489
  var sepia = document.querySelector('#' + this.element.id + '_sepiaCanvas');
4479
- ctx = sepia.getContext('2d');
4480
- sepia.style.width = '100px';
4481
- sepia.style.height = '100px';
4482
- ctx.filter = this.updateAdjustment('sepia', null, true);
4483
- ctx.drawImage(this.inMemoryCanvas, 0, 0, 300, 150);
4490
+ if (!isNullOrUndefined(sepia)) {
4491
+ ctx = sepia.getContext('2d');
4492
+ sepia.style.width = '100px';
4493
+ sepia.style.height = '100px';
4494
+ ctx.filter = this.updateAdjustment('sepia', null, true);
4495
+ ctx.drawImage(this.inMemoryCanvas, 0, 0, 300, 150);
4496
+ }
4484
4497
  var invert = document.querySelector('#' + this.element.id + '_invertCanvas');
4485
- ctx = invert.getContext('2d');
4486
- invert.style.width = '100px';
4487
- invert.style.height = '100px';
4488
- ctx.filter = this.updateAdjustment('invert', null, true);
4489
- ctx.drawImage(this.inMemoryCanvas, 0, 0, 300, 150);
4498
+ if (!isNullOrUndefined(invert)) {
4499
+ ctx = invert.getContext('2d');
4500
+ invert.style.width = '100px';
4501
+ invert.style.height = '100px';
4502
+ ctx.filter = this.updateAdjustment('invert', null, true);
4503
+ ctx.drawImage(this.inMemoryCanvas, 0, 0, 300, 150);
4504
+ }
4490
4505
  };
4491
4506
  ImageEditor.prototype.callUpdateCurrentTransformedState = function () {
4492
4507
  var tempObjColl = extend([], this.objColl, [], true);
@@ -6255,7 +6270,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
6255
6270
  _this.currObjType.isUndoZoom = false;
6256
6271
  _this.lowerCanvas.style.display = 'block';
6257
6272
  }
6258
- _this.isUndoRedo = false;
6273
+ _this.isUndoRedo = _this.isErrorImage = false;
6259
6274
  if (Browser.isDevice) {
6260
6275
  if (_this.isToolbar() && (!isNullOrUndefined(document.getElementById(_this.element.id + '_toolbar'))) &&
6261
6276
  (!isNullOrUndefined(getComponent(document.getElementById(_this.element.id + '_toolbar'), 'toolbar')))) {
@@ -6276,6 +6291,10 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
6276
6291
  _this.initToolbarItem(false, false, null);
6277
6292
  }
6278
6293
  };
6294
+ this.baseImg.onerror = function () {
6295
+ hideSpinner(_this.element);
6296
+ _this.isErrorImage = true;
6297
+ };
6279
6298
  };
6280
6299
  ImageEditor.prototype.refreshActiveObj = function () {
6281
6300
  this.activeObj = {};
@@ -6743,7 +6762,8 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
6743
6762
  else if (!isShape && !isNullOrUndefined(activeObj.shape)) {
6744
6763
  this.activeObj = activeObj;
6745
6764
  var index = this.getCurrentIndex();
6746
- if ((!isNullOrUndefined(index) && JSON.stringify(this.activeObj.activePoint) === JSON.stringify(this.objColl[index].activePoint))) {
6765
+ if ((!isNullOrUndefined(index) &&
6766
+ JSON.stringify(this.activeObj.activePoint) === JSON.stringify(this.objColl[index].activePoint))) {
6747
6767
  this.objColl.splice(index, 1);
6748
6768
  }
6749
6769
  else if (isNullOrUndefined(this.activeObj.currIndex)) {
@@ -13242,7 +13262,28 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
13242
13262
  * @returns {ImageData}.
13243
13263
  */
13244
13264
  ImageEditor.prototype.getImageData = function () {
13265
+ if (!isNullOrUndefined(this.activeObj.shape)) {
13266
+ this.performCancel();
13267
+ }
13268
+ var currentObj;
13269
+ if (this.defaultZoomFactor > 0) {
13270
+ currentObj = this.getCurrentObj();
13271
+ currentObj.objColl = extend([], this.objColl, [], true);
13272
+ currentObj.pointColl = extend([], this.pointColl, [], true);
13273
+ currentObj.afterCropActions = extend([], this.afterCropActions, [], true);
13274
+ }
13275
+ this.resetZoom();
13245
13276
  var data = this.lowerContext.getImageData(this.destLeft, this.destTop, this.destWidth, this.destHeight);
13277
+ if (!isNullOrUndefined(currentObj)) {
13278
+ this.setCurrentObj(currentObj);
13279
+ this.objColl = extend([], currentObj.objColl, [], true);
13280
+ this.pointColl = extend([], currentObj.pointColl, [], true);
13281
+ this.freehandCounter = this.pointColl.length;
13282
+ this.lowerContext.filter = 'none';
13283
+ this.zoomObjColl();
13284
+ this.zoomFreehandDrawColl();
13285
+ this.lowerContext.filter = currentObj.filter;
13286
+ }
13246
13287
  return data;
13247
13288
  };
13248
13289
  /**
@@ -13265,12 +13306,15 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
13265
13306
  }
13266
13307
  if (this.defToolbarItems.length === 0 &&
13267
13308
  (isNullOrUndefined(document.getElementById(this.element.id + '_toolbar')))) {
13268
- this.toolbarHeight = 0;
13269
- }
13270
- if (isNullOrUndefined(this.toolbarTemplate)) {
13271
- this.reset();
13272
- this.update();
13309
+ if (isNullOrUndefined(this.toolbarTemplate)) {
13310
+ this.toolbarHeight = 0;
13311
+ }
13312
+ else if (!isNullOrUndefined(this.element.querySelector('#' + this.element.id + '_toolbarArea'))) {
13313
+ this.toolbarHeight = this.element.querySelector('#' + this.element.id + '_toolbarArea').clientHeight;
13314
+ }
13273
13315
  }
13316
+ this.reset();
13317
+ this.update();
13274
13318
  this.degree = 0;
13275
13319
  this.zoomFactor = 0;
13276
13320
  this.isImageLoaded = false;
@@ -13312,7 +13356,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
13312
13356
  * @returns {void}.
13313
13357
  */
13314
13358
  ImageEditor.prototype.reset = function () {
13315
- if (!this.disabled) {
13359
+ if (!this.disabled && !this.isErrorImage) {
13316
13360
  this.inMemoryContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
13317
13361
  this.inMemoryContext.clearRect(0, 0, this.lowerCanvas.height, this.lowerCanvas.width);
13318
13362
  this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
@@ -13383,7 +13427,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
13383
13427
  this.rotatedDestPoints = { startX: 0, startY: 0, width: 0, height: 0 };
13384
13428
  this.croppedDegree = 0;
13385
13429
  this.freehandDrawHoveredIndex = this.freehandDrawSelectedIndex = null;
13386
- this.isFreehandDrawingPoint = this.isFreehandDrawEditing = false;
13430
+ this.isFreehandDrawingPoint = this.isFreehandDrawEditing = this.isErrorImage = false;
13387
13431
  this.tempFreeHandDrawEditingStyles = { strokeColor: null, fillColor: null, strokeWidth: null };
13388
13432
  this.totalPannedInternalPoint = { x: 0, y: 0 };
13389
13433
  this.totalPannedClientPoint = { x: 0, y: 0 };
@@ -13538,6 +13582,11 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
13538
13582
  */
13539
13583
  ImageEditor.prototype.select = function (type, startX, startY, width, height) {
13540
13584
  if (!this.disabled && this.isImageLoaded) {
13585
+ var previousObj = this.getCurrentObj();
13586
+ previousObj.objColl = extend([], this.objColl, [], true);
13587
+ previousObj.pointColl = extend([], this.pointColl, [], true);
13588
+ previousObj.afterCropActions = this.afterCropActions;
13589
+ this.previousCropCurrentObj = previousObj;
13541
13590
  if (this.zoomFactor > 0 && !isNullOrUndefined(this.activeObj.shape) && this.activeObj.shape.split('-')[0] === 'crop' && isNullOrUndefined(this.currentSelectionPoint)) {
13542
13591
  this.currentSelectionPoint = extend({}, this.activeObj, {}, true);
13543
13592
  }