@syncfusion/ej2-image-editor 21.1.35 → 21.1.39

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);
@@ -5124,6 +5139,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
5124
5139
  this.activeObj.activePoint.height = this.activeObj.activePoint.endY - this.activeObj.activePoint.startY;
5125
5140
  this.updateActiveObject(this.activeObj.activePoint, this.activeObj);
5126
5141
  }
5142
+ this.updateSelectionInsert();
5127
5143
  this.drawObject('duplicate', this.activeObj, null, null, true);
5128
5144
  };
5129
5145
  ImageEditor.prototype.clearOuterCanvas = function (context) {
@@ -6255,7 +6271,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
6255
6271
  _this.currObjType.isUndoZoom = false;
6256
6272
  _this.lowerCanvas.style.display = 'block';
6257
6273
  }
6258
- _this.isUndoRedo = false;
6274
+ _this.isUndoRedo = _this.isErrorImage = false;
6259
6275
  if (Browser.isDevice) {
6260
6276
  if (_this.isToolbar() && (!isNullOrUndefined(document.getElementById(_this.element.id + '_toolbar'))) &&
6261
6277
  (!isNullOrUndefined(getComponent(document.getElementById(_this.element.id + '_toolbar'), 'toolbar')))) {
@@ -6276,6 +6292,10 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
6276
6292
  _this.initToolbarItem(false, false, null);
6277
6293
  }
6278
6294
  };
6295
+ this.baseImg.onerror = function () {
6296
+ hideSpinner(_this.element);
6297
+ _this.isErrorImage = true;
6298
+ };
6279
6299
  };
6280
6300
  ImageEditor.prototype.refreshActiveObj = function () {
6281
6301
  this.activeObj = {};
@@ -6743,7 +6763,8 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
6743
6763
  else if (!isShape && !isNullOrUndefined(activeObj.shape)) {
6744
6764
  this.activeObj = activeObj;
6745
6765
  var index = this.getCurrentIndex();
6746
- if ((!isNullOrUndefined(index) && JSON.stringify(this.activeObj.activePoint) === JSON.stringify(this.objColl[index].activePoint))) {
6766
+ if ((!isNullOrUndefined(index) &&
6767
+ JSON.stringify(this.activeObj.activePoint) === JSON.stringify(this.objColl[index].activePoint))) {
6747
6768
  this.objColl.splice(index, 1);
6748
6769
  }
6749
6770
  else if (isNullOrUndefined(this.activeObj.currIndex)) {
@@ -12819,6 +12840,13 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
12819
12840
  width: width, height: width };
12820
12841
  }
12821
12842
  this.activeObj.shape = cropShape.toLowerCase();
12843
+ this.updateSelectionInsert();
12844
+ if (this.activeObj.activePoint.startX !== 0 || this.activeObj.activePoint.startY !== 0 ||
12845
+ this.activeObj.activePoint.width !== 0 || this.activeObj.activePoint.height !== 0) {
12846
+ points = { startX: this.activeObj.activePoint.startX, startY: this.activeObj.activePoint.startY,
12847
+ endX: this.activeObj.activePoint.endX, endY: this.activeObj.activePoint.endY,
12848
+ width: this.activeObj.activePoint.width, height: this.activeObj.activePoint.height };
12849
+ }
12822
12850
  this.drawObject('duplicate', null, true, points);
12823
12851
  }
12824
12852
  };
@@ -13242,7 +13270,28 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
13242
13270
  * @returns {ImageData}.
13243
13271
  */
13244
13272
  ImageEditor.prototype.getImageData = function () {
13273
+ if (!isNullOrUndefined(this.activeObj.shape)) {
13274
+ this.performCancel();
13275
+ }
13276
+ var currentObj;
13277
+ if (this.defaultZoomFactor > 0) {
13278
+ currentObj = this.getCurrentObj();
13279
+ currentObj.objColl = extend([], this.objColl, [], true);
13280
+ currentObj.pointColl = extend([], this.pointColl, [], true);
13281
+ currentObj.afterCropActions = extend([], this.afterCropActions, [], true);
13282
+ }
13283
+ this.resetZoom();
13245
13284
  var data = this.lowerContext.getImageData(this.destLeft, this.destTop, this.destWidth, this.destHeight);
13285
+ if (!isNullOrUndefined(currentObj)) {
13286
+ this.setCurrentObj(currentObj);
13287
+ this.objColl = extend([], currentObj.objColl, [], true);
13288
+ this.pointColl = extend([], currentObj.pointColl, [], true);
13289
+ this.freehandCounter = this.pointColl.length;
13290
+ this.lowerContext.filter = 'none';
13291
+ this.zoomObjColl();
13292
+ this.zoomFreehandDrawColl();
13293
+ this.lowerContext.filter = currentObj.filter;
13294
+ }
13246
13295
  return data;
13247
13296
  };
13248
13297
  /**
@@ -13265,12 +13314,15 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
13265
13314
  }
13266
13315
  if (this.defToolbarItems.length === 0 &&
13267
13316
  (isNullOrUndefined(document.getElementById(this.element.id + '_toolbar')))) {
13268
- this.toolbarHeight = 0;
13269
- }
13270
- if (isNullOrUndefined(this.toolbarTemplate)) {
13271
- this.reset();
13272
- this.update();
13317
+ if (isNullOrUndefined(this.toolbarTemplate)) {
13318
+ this.toolbarHeight = 0;
13319
+ }
13320
+ else if (!isNullOrUndefined(this.element.querySelector('#' + this.element.id + '_toolbarArea'))) {
13321
+ this.toolbarHeight = this.element.querySelector('#' + this.element.id + '_toolbarArea').clientHeight;
13322
+ }
13273
13323
  }
13324
+ this.reset();
13325
+ this.update();
13274
13326
  this.degree = 0;
13275
13327
  this.zoomFactor = 0;
13276
13328
  this.isImageLoaded = false;
@@ -13312,7 +13364,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
13312
13364
  * @returns {void}.
13313
13365
  */
13314
13366
  ImageEditor.prototype.reset = function () {
13315
- if (!this.disabled) {
13367
+ if (!this.disabled && !this.isErrorImage) {
13316
13368
  this.inMemoryContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
13317
13369
  this.inMemoryContext.clearRect(0, 0, this.lowerCanvas.height, this.lowerCanvas.width);
13318
13370
  this.lowerContext.clearRect(0, 0, this.lowerCanvas.width, this.lowerCanvas.height);
@@ -13383,7 +13435,7 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
13383
13435
  this.rotatedDestPoints = { startX: 0, startY: 0, width: 0, height: 0 };
13384
13436
  this.croppedDegree = 0;
13385
13437
  this.freehandDrawHoveredIndex = this.freehandDrawSelectedIndex = null;
13386
- this.isFreehandDrawingPoint = this.isFreehandDrawEditing = false;
13438
+ this.isFreehandDrawingPoint = this.isFreehandDrawEditing = this.isErrorImage = false;
13387
13439
  this.tempFreeHandDrawEditingStyles = { strokeColor: null, fillColor: null, strokeWidth: null };
13388
13440
  this.totalPannedInternalPoint = { x: 0, y: 0 };
13389
13441
  this.totalPannedClientPoint = { x: 0, y: 0 };
@@ -13538,6 +13590,11 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
13538
13590
  */
13539
13591
  ImageEditor.prototype.select = function (type, startX, startY, width, height) {
13540
13592
  if (!this.disabled && this.isImageLoaded) {
13593
+ var previousObj = this.getCurrentObj();
13594
+ previousObj.objColl = extend([], this.objColl, [], true);
13595
+ previousObj.pointColl = extend([], this.pointColl, [], true);
13596
+ previousObj.afterCropActions = this.afterCropActions;
13597
+ this.previousCropCurrentObj = previousObj;
13541
13598
  if (this.zoomFactor > 0 && !isNullOrUndefined(this.activeObj.shape) && this.activeObj.shape.split('-')[0] === 'crop' && isNullOrUndefined(this.currentSelectionPoint)) {
13542
13599
  this.currentSelectionPoint = extend({}, this.activeObj, {}, true);
13543
13600
  }
@@ -13594,6 +13651,13 @@ var ImageEditor = /** @__PURE__ @class */ (function (_super) {
13594
13651
  }
13595
13652
  }
13596
13653
  };
13654
+ ImageEditor.prototype.updateSelectionInsert = function () {
13655
+ var shapeSettings = this.updatePreviousShapeSettings();
13656
+ var shapeChangingArgs = { action: 'insert', previousShapeSettings: shapeSettings,
13657
+ currentShapeSettings: shapeSettings };
13658
+ this.trigger('shapeChanging', shapeChangingArgs);
13659
+ this.updateShapeChangeEventArgs(shapeChangingArgs.currentShapeSettings);
13660
+ };
13597
13661
  /**
13598
13662
  * Enable or disable a freehand drawing option in an Image Editor.
13599
13663
  *