@syncfusion/ej2-inputs 19.3.57 → 19.4.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +1 -1
  3. package/common.d.ts +4 -0
  4. package/common.js +4 -0
  5. package/dist/ej2-inputs.umd.min.js +2 -2
  6. package/dist/ej2-inputs.umd.min.js.map +1 -1
  7. package/dist/es6/ej2-inputs.es2015.js +1117 -8
  8. package/dist/es6/ej2-inputs.es2015.js.map +1 -1
  9. package/dist/es6/ej2-inputs.es5.js +1152 -8
  10. package/dist/es6/ej2-inputs.es5.js.map +1 -1
  11. package/dist/global/ej2-inputs.min.js +2 -2
  12. package/dist/global/ej2-inputs.min.js.map +1 -1
  13. package/dist/global/index.d.ts +1 -1
  14. package/package.json +9 -9
  15. package/signature.d.ts +4 -0
  16. package/signature.js +4 -0
  17. package/src/common/index.d.ts +4 -0
  18. package/src/common/index.js +4 -0
  19. package/src/common/signature-base.d.ts +320 -0
  20. package/src/common/signature-base.js +946 -0
  21. package/src/index.d.ts +2 -0
  22. package/src/index.js +2 -0
  23. package/src/input/input.js +10 -6
  24. package/src/numerictextbox/numerictextbox.js +5 -0
  25. package/src/signature/index.d.ts +5 -0
  26. package/src/signature/index.js +4 -0
  27. package/src/signature/signature-model.d.ts +131 -0
  28. package/src/signature/signature.d.ts +167 -0
  29. package/src/signature/signature.js +171 -0
  30. package/src/slider/slider.d.ts +1 -0
  31. package/src/slider/slider.js +16 -1
  32. package/styles/bootstrap-dark.css +43 -16
  33. package/styles/bootstrap-dark.scss +1 -0
  34. package/styles/bootstrap.css +43 -16
  35. package/styles/bootstrap.scss +1 -0
  36. package/styles/bootstrap4.css +43 -16
  37. package/styles/bootstrap4.scss +1 -0
  38. package/styles/bootstrap5-dark.css +46 -41
  39. package/styles/bootstrap5-dark.scss +1 -0
  40. package/styles/bootstrap5.css +46 -41
  41. package/styles/bootstrap5.scss +1 -0
  42. package/styles/color-picker/_fabric-dark-definition.scss +1 -1
  43. package/styles/color-picker/_fluent-definition.scss +134 -0
  44. package/styles/color-picker/_layout.scss +5 -5
  45. package/styles/color-picker/_theme.scss +16 -15
  46. package/styles/color-picker/bootstrap-dark.css +20 -0
  47. package/styles/color-picker/bootstrap.css +20 -0
  48. package/styles/color-picker/bootstrap4.css +20 -0
  49. package/styles/color-picker/bootstrap5-dark.css +22 -20
  50. package/styles/color-picker/bootstrap5.css +22 -20
  51. package/styles/color-picker/fabric-dark.css +23 -3
  52. package/styles/color-picker/fabric.css +20 -0
  53. package/styles/color-picker/highcontrast-light.css +20 -0
  54. package/styles/color-picker/highcontrast.css +20 -0
  55. package/styles/color-picker/icons/_fluent.scss +10 -0
  56. package/styles/color-picker/material-dark.css +20 -0
  57. package/styles/color-picker/material.css +20 -0
  58. package/styles/color-picker/tailwind-dark.css +20 -0
  59. package/styles/color-picker/tailwind.css +20 -0
  60. package/styles/fabric-dark.css +46 -19
  61. package/styles/fabric-dark.scss +1 -0
  62. package/styles/fabric.css +43 -16
  63. package/styles/fabric.scss +1 -0
  64. package/styles/highcontrast-light.css +43 -16
  65. package/styles/highcontrast-light.scss +1 -0
  66. package/styles/highcontrast.css +43 -16
  67. package/styles/highcontrast.scss +1 -0
  68. package/styles/input/_fluent-definition.scss +321 -0
  69. package/styles/input/_layout.scss +138 -37
  70. package/styles/input/_theme.scss +42 -24
  71. package/styles/input/bootstrap-dark.css +13 -16
  72. package/styles/input/bootstrap.css +13 -16
  73. package/styles/input/bootstrap4.css +13 -16
  74. package/styles/input/bootstrap5-dark.css +13 -16
  75. package/styles/input/bootstrap5.css +13 -16
  76. package/styles/input/fabric-dark.css +13 -16
  77. package/styles/input/fabric.css +13 -16
  78. package/styles/input/highcontrast-light.css +13 -16
  79. package/styles/input/highcontrast.css +13 -16
  80. package/styles/input/icons/_fluent.scss +17 -0
  81. package/styles/input/material-dark.css +13 -16
  82. package/styles/input/material.css +13 -16
  83. package/styles/input/tailwind-dark.css +13 -16
  84. package/styles/input/tailwind.css +13 -16
  85. package/styles/maskedtextbox/_fluent-definition.scss +7 -0
  86. package/styles/maskedtextbox/_theme.scss +2 -2
  87. package/styles/material-dark.css +43 -16
  88. package/styles/material-dark.scss +1 -0
  89. package/styles/material.css +43 -16
  90. package/styles/material.scss +1 -0
  91. package/styles/numerictextbox/_fluent-definition.scss +5 -0
  92. package/styles/numerictextbox/_theme.scss +18 -0
  93. package/styles/numerictextbox/icons/_fluent.scss +12 -0
  94. package/styles/signature/_all.scss +2 -0
  95. package/styles/signature/_bootstrap-dark-definition.scss +3 -0
  96. package/styles/signature/_bootstrap-definition.scss +3 -0
  97. package/styles/signature/_bootstrap4-definition.scss +3 -0
  98. package/styles/signature/_bootstrap5-dark-definition.scss +1 -0
  99. package/styles/signature/_bootstrap5-definition.scss +3 -0
  100. package/styles/signature/_fabric-dark-definition.scss +3 -0
  101. package/styles/signature/_fabric-definition.scss +3 -0
  102. package/styles/signature/_fluent-definition.scss +3 -0
  103. package/styles/signature/_highcontrast-definition.scss +3 -0
  104. package/styles/signature/_highcontrast-light-definition.scss +3 -0
  105. package/styles/signature/_layout.scss +5 -0
  106. package/styles/signature/_material-dark-definition.scss +3 -0
  107. package/styles/signature/_material-definition.scss +3 -0
  108. package/styles/signature/_tailwind-dark-definition.scss +1 -0
  109. package/styles/signature/_tailwind-definition.scss +3 -0
  110. package/styles/signature/_theme.scss +7 -0
  111. package/styles/signature/bootstrap-dark.css +9 -0
  112. package/styles/signature/bootstrap-dark.scss +3 -0
  113. package/styles/signature/bootstrap.css +9 -0
  114. package/styles/signature/bootstrap.scss +3 -0
  115. package/styles/signature/bootstrap4.css +9 -0
  116. package/styles/signature/bootstrap4.scss +3 -0
  117. package/styles/signature/bootstrap5-dark.css +9 -0
  118. package/styles/signature/bootstrap5-dark.scss +3 -0
  119. package/styles/signature/bootstrap5.css +9 -0
  120. package/styles/signature/bootstrap5.scss +3 -0
  121. package/styles/signature/fabric-dark.css +9 -0
  122. package/styles/signature/fabric-dark.scss +3 -0
  123. package/styles/signature/fabric.css +9 -0
  124. package/styles/signature/fabric.scss +3 -0
  125. package/styles/signature/highcontrast-light.css +9 -0
  126. package/styles/signature/highcontrast-light.scss +3 -0
  127. package/styles/signature/highcontrast.css +9 -0
  128. package/styles/signature/highcontrast.scss +3 -0
  129. package/styles/signature/material-dark.css +10 -0
  130. package/styles/signature/material-dark.scss +3 -0
  131. package/styles/signature/material.css +10 -0
  132. package/styles/signature/material.scss +3 -0
  133. package/styles/signature/tailwind-dark.css +10 -0
  134. package/styles/signature/tailwind-dark.scss +3 -0
  135. package/styles/signature/tailwind.css +10 -0
  136. package/styles/signature/tailwind.scss +3 -0
  137. package/styles/slider/_bootstrap5-definition.scss +2 -2
  138. package/styles/slider/_fluent-definition.scss +94 -0
  139. package/styles/slider/_layout.scss +7 -2
  140. package/styles/slider/_tailwind-definition.scss +2 -2
  141. package/styles/slider/bootstrap5-dark.css +1 -5
  142. package/styles/slider/bootstrap5.css +1 -5
  143. package/styles/slider/tailwind-dark.css +1 -5
  144. package/styles/slider/tailwind.css +1 -5
  145. package/styles/tailwind-dark.css +45 -21
  146. package/styles/tailwind-dark.scss +1 -0
  147. package/styles/tailwind.css +45 -21
  148. package/styles/tailwind.scss +1 -0
  149. package/styles/textbox/_fluent-definition.scss +0 -0
  150. package/styles/uploader/_fluent-definition.scss +234 -0
  151. package/styles/uploader/_layout.scss +99 -8
  152. package/styles/uploader/_theme.scss +5 -2
  153. package/styles/uploader/icons/_fluent.scss +34 -0
@@ -188,7 +188,7 @@ var Input;
188
188
  if (args.floatLabelType === 'Auto') {
189
189
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
190
190
  args.element.addEventListener('input', function (event) {
191
- updateLabelState(args.element.value, floatLabelElement);
191
+ updateLabelState(args.element.value, floatLabelElement, args.element);
192
192
  });
193
193
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
194
194
  args.element.addEventListener('blur', function (event) {
@@ -238,7 +238,8 @@ var Input;
238
238
  addClass([button], CLASSNAMES.CLEARICONHIDE);
239
239
  }
240
240
  }
241
- function updateLabelState(value, label) {
241
+ function updateLabelState(value, label, element) {
242
+ if (element === void 0) { element = null; }
242
243
  if (value) {
243
244
  addClass([label], CLASSNAMES.LABELTOP);
244
245
  if (label.classList.contains(CLASSNAMES.LABELBOTTOM)) {
@@ -246,10 +247,13 @@ var Input;
246
247
  }
247
248
  }
248
249
  else {
249
- if (label.classList.contains(CLASSNAMES.LABELTOP)) {
250
- removeClass([label], CLASSNAMES.LABELTOP);
250
+ var isNotFocused = element != null ? element !== document.activeElement : true;
251
+ if (isNotFocused) {
252
+ if (label.classList.contains(CLASSNAMES.LABELTOP)) {
253
+ removeClass([label], CLASSNAMES.LABELTOP);
254
+ }
255
+ addClass([label], CLASSNAMES.LABELBOTTOM);
251
256
  }
252
- addClass([label], CLASSNAMES.LABELBOTTOM);
253
257
  }
254
258
  }
255
259
  function getParentNode(element) {
@@ -318,7 +322,7 @@ var Input;
318
322
  var parent = getParentNode(element);
319
323
  if (parent.classList.contains(CLASSNAMES.FLOATINPUT) && floatLabelType === 'Auto') {
320
324
  var label = getParentNode(element).getElementsByClassName('e-float-text')[0];
321
- updateLabelState(element.value, label);
325
+ updateLabelState(element.value, label, element);
322
326
  }
323
327
  }
324
328
  /**
@@ -1434,6 +1438,10 @@ var NumericTextBox = /** @__PURE__ @class */ (function (_super) {
1434
1438
  }
1435
1439
  _this.element.setSelectionRange(_this.element.selectionStart, _this.element.selectionStart);
1436
1440
  }
1441
+ if (_this.element.value[_this.element.selectionStart - 1] === decimalSeparator && _this.decimals === 0 && _this.validateDecimalOnType) {
1442
+ _this.element.value = _this.element.value.substring(0, prevPos) +
1443
+ _this.element.value.substring(currentPos, _this.element.value.length);
1444
+ }
1437
1445
  }
1438
1446
  _this.prevVal = _this.element.value;
1439
1447
  }
@@ -1803,6 +1811,7 @@ var NumericTextBox = /** @__PURE__ @class */ (function (_super) {
1803
1811
  }
1804
1812
  };
1805
1813
  NumericTextBox.prototype.mouseUpOnSpinner = function (event) {
1814
+ this.prevValue = this.value;
1806
1815
  if (this.isPrevFocused) {
1807
1816
  this.element.focus();
1808
1817
  if (!Browser.isDevice) {
@@ -4435,9 +4444,11 @@ var Slider = /** @__PURE__ @class */ (function (_super) {
4435
4444
  this.sliderBarClick(e);
4436
4445
  if (e.currentTarget === this.firstHandle) {
4437
4446
  this.firstHandle.classList.add(classNames.sliderHandleFocused);
4447
+ this.firstHandle.classList.add(classNames.sliderTabHandle);
4438
4448
  }
4439
4449
  else {
4440
4450
  this.secondHandle.classList.add(classNames.sliderHandleFocused);
4451
+ this.secondHandle.classList.add(classNames.sliderTabHandle);
4441
4452
  }
4442
4453
  EventHandler.add(document, 'mousemove touchmove', this.sliderBarMove, this);
4443
4454
  EventHandler.add(document, 'mouseup touchend', this.sliderBarUp, this);
@@ -4765,7 +4776,7 @@ var Slider = /** @__PURE__ @class */ (function (_super) {
4765
4776
  this.initializeTooltipProps();
4766
4777
  };
4767
4778
  Slider.prototype.initializeTooltipProps = function () {
4768
- var tooltipShowOn = this.isMaterialTooltip ? 'Always' : (this.tooltip.showOn === 'Auto' ? 'Hover' : this.tooltip.showOn);
4779
+ var tooltipShowOn = (this.tooltip.showOn === 'Auto' ? 'Hover' : this.tooltip.showOn);
4769
4780
  this.setProperties({ tooltip: { showOn: tooltipShowOn } }, true);
4770
4781
  this.tooltipObj.position = this.tooltipPlacement();
4771
4782
  this.tooltipCollision(this.tooltipObj.position);
@@ -4851,6 +4862,11 @@ var Slider = /** @__PURE__ @class */ (function (_super) {
4851
4862
  this.getHandle().classList.add('e-large-thumb-size');
4852
4863
  }
4853
4864
  };
4865
+ Slider.prototype.focusHandle = function () {
4866
+ if (!this.getHandle().classList.contains(classNames.sliderTabHandle)) {
4867
+ this.getHandle().classList.add(classNames.sliderTabHandle);
4868
+ }
4869
+ };
4854
4870
  Slider.prototype.repeatHandlerUp = function (e) {
4855
4871
  this.changeEvent('changed', e);
4856
4872
  this.closeTooltip();
@@ -5243,6 +5259,7 @@ var Slider = /** @__PURE__ @class */ (function (_super) {
5243
5259
  }
5244
5260
  this.tooltipToggle(this.getHandle());
5245
5261
  this.getHandle().focus();
5262
+ this.focusHandle();
5246
5263
  if (args.currentTarget.classList.contains(classNames.firstButton)) {
5247
5264
  EventHandler.add(this.firstBtn, 'mouseup touchend', this.buttonUp, this);
5248
5265
  }
@@ -6187,6 +6204,7 @@ var Slider = /** @__PURE__ @class */ (function (_super) {
6187
6204
  event.preventDefault();
6188
6205
  this.focusSliderElement();
6189
6206
  this.sliderBarClick(event);
6207
+ this.focusHandle();
6190
6208
  };
6191
6209
  Slider.prototype.wireEvents = function () {
6192
6210
  this.onresize = this.reposition.bind(this);
@@ -6270,6 +6288,12 @@ var Slider = /** @__PURE__ @class */ (function (_super) {
6270
6288
  }
6271
6289
  else {
6272
6290
  this.sliderContainer.classList.remove(classNames.sliderHover);
6291
+ var curTarget = event.currentTarget;
6292
+ if (this.tooltip.isVisible && this.tooltip.showOn !== 'Always' && this.tooltipObj && this.isMaterialTooltip &&
6293
+ !curTarget.classList.contains(classNames.sliderHandleFocused) &&
6294
+ !curTarget.classList.contains(classNames.sliderTabHandle)) {
6295
+ this.closeMaterialTooltip();
6296
+ }
6273
6297
  }
6274
6298
  }
6275
6299
  };
@@ -13682,9 +13706,1129 @@ var TextBox = /** @__PURE__ @class */ (function (_super) {
13682
13706
  * Uploader modules
13683
13707
  */
13684
13708
 
13709
+ var __extends$8 = (undefined && undefined.__extends) || (function () {
13710
+ var extendStatics = function (d, b) {
13711
+ extendStatics = Object.setPrototypeOf ||
13712
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
13713
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
13714
+ return extendStatics(d, b);
13715
+ };
13716
+ return function (d, b) {
13717
+ extendStatics(d, b);
13718
+ function __() { this.constructor = d; }
13719
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13720
+ };
13721
+ })();
13722
+ var SignatureBase = /** @__PURE__ @class */ (function (_super) {
13723
+ __extends$8(SignatureBase, _super);
13724
+ function SignatureBase() {
13725
+ var _this = _super !== null && _super.apply(this, arguments) || this;
13726
+ /* minDistance(distance between the two point) was calaculated for smoothness.*/
13727
+ _this.minDistance = 5;
13728
+ _this.previous = 0;
13729
+ /* interval handles for the smoothness in the mouse move event.*/
13730
+ _this.interval = 30;
13731
+ _this.timeout = null;
13732
+ _this.isSignatureEmpty = true;
13733
+ _this.backgroundLoaded = null;
13734
+ _this.clearArray = [];
13735
+ _this.isBlazor = false;
13736
+ return _this;
13737
+ }
13738
+ /**
13739
+ * To Initialize the component rendering
13740
+ *
13741
+ * @private
13742
+ * @param {HTMLCanvasElement} element - Specifies the canvas element.
13743
+ * @param {parameter} parameter - Specifies only for the blazor parameter.
13744
+ * @param {BlazorDotnetObject} dotnetRef - Specifies for blazor client to server communication.
13745
+ * @returns {void}
13746
+ */
13747
+ SignatureBase.prototype.initialize = function (element, parameter, dotnetRef) {
13748
+ this.element = element;
13749
+ this.canvasContext = this.element.getContext('2d');
13750
+ this.canvasContext.canvas.tabIndex = 0;
13751
+ if (parameter) {
13752
+ this.setBlazorParameter(parameter);
13753
+ this.dotnetRef = dotnetRef;
13754
+ }
13755
+ this.setHTMLProperties();
13756
+ if (isNullOrUndefined(this.signatureValue)) {
13757
+ this.updateSnapCollection(true);
13758
+ }
13759
+ this.wireEvents();
13760
+ this.isSignatureEmpty = true;
13761
+ if (!this.isBlazor) {
13762
+ this.trigger('created', null);
13763
+ }
13764
+ };
13765
+ SignatureBase.prototype.setBlazorParameter = function (parameter) {
13766
+ this.isBlazor = true;
13767
+ this.backgroundColor = parameter.backgroundColor;
13768
+ this.backgroundImage = parameter.backgroundImage;
13769
+ this.disabled = parameter.disabled;
13770
+ this.isReadOnly = parameter.isReadOnly;
13771
+ this.maxStrokeWidth = parameter.maxStrokeWidth || 2;
13772
+ this.minStrokeWidth = parameter.minStrokeWidth || 0.5;
13773
+ this.velocity = parameter.velocity || 0.7;
13774
+ this.strokeColor = parameter.strokeColor || '#000000';
13775
+ this.saveWithBackground = parameter.saveWithBackground;
13776
+ this.interval = 30;
13777
+ this.previous = 0;
13778
+ this.minDistance = 5;
13779
+ this.signatureValue = parameter.signatureValue;
13780
+ if (this.signatureValue) {
13781
+ this.loadPersistedSignature();
13782
+ }
13783
+ };
13784
+ SignatureBase.prototype.wireEvents = function () {
13785
+ if (isNullOrUndefined(this.pointColl) && !this.isReadOnly && !this.disabled) {
13786
+ EventHandler.add(this.canvasContext.canvas, 'mousedown touchstart', this.mouseDownHandler, this);
13787
+ EventHandler.add(this.canvasContext.canvas, 'keydown', this.keyboardHandler, this);
13788
+ window.addEventListener('resize', this.resizeHandler.bind(this));
13789
+ }
13790
+ else if (this.pointColl) {
13791
+ EventHandler.add(this.canvasContext.canvas, 'mousemove touchmove', this.mouseMoveHandler, this);
13792
+ EventHandler.add(this.canvasContext.canvas, 'mouseup touchend', this.mouseUpHandler, this);
13793
+ EventHandler.add(document, 'mouseup', this.mouseUpHandler, this);
13794
+ }
13795
+ };
13796
+ SignatureBase.prototype.unwireEvents = function (type) {
13797
+ if (type === 'mouseup' || type === 'touchend') {
13798
+ EventHandler.remove(this.canvasContext.canvas, 'mousemove touchmove', this.mouseMoveHandler);
13799
+ EventHandler.remove(this.canvasContext.canvas, 'mouseup touchend', this.mouseUpHandler);
13800
+ EventHandler.remove(document, 'mouseup', this.mouseUpHandler);
13801
+ }
13802
+ else {
13803
+ EventHandler.remove(this.canvasContext.canvas, 'mousedown touchstart', this.mouseDownHandler);
13804
+ EventHandler.remove(this.canvasContext.canvas, 'mousemove touchmove', this.mouseMoveHandler);
13805
+ EventHandler.remove(this.canvasContext.canvas, 'mouseup touchend', this.mouseUpHandler);
13806
+ EventHandler.remove(document, 'mouseup', this.mouseUpHandler);
13807
+ EventHandler.remove(this.canvasContext.canvas, 'keydown', this.keyboardHandler);
13808
+ window.removeEventListener('resize', this.resizeHandler);
13809
+ }
13810
+ };
13811
+ SignatureBase.prototype.setHTMLProperties = function () {
13812
+ if (this.element.height === 150) {
13813
+ this.element.height = this.element.offsetHeight;
13814
+ }
13815
+ if (this.element.width === 300) {
13816
+ this.element.width = this.element.offsetWidth;
13817
+ }
13818
+ this.canvasContext.scale(1, 1);
13819
+ this.canvasContext.fillStyle = this.strokeColor;
13820
+ if (this.backgroundImage) {
13821
+ this.canvasContext.canvas.style.backgroundImage = 'url(' + this.backgroundImage + ')';
13822
+ }
13823
+ else if (this.backgroundColor) {
13824
+ this.canvasContext.canvas.style.backgroundColor = this.backgroundColor;
13825
+ }
13826
+ };
13827
+ SignatureBase.prototype.mouseDownHandler = function (e) {
13828
+ if (e.buttons === 1 || e.buttons === 2 || e.type === 'touchstart') {
13829
+ if (e.type === 'touchstart') {
13830
+ e.preventDefault();
13831
+ e.stopPropagation();
13832
+ }
13833
+ this.beginStroke(e);
13834
+ this.wireEvents();
13835
+ }
13836
+ };
13837
+ SignatureBase.prototype.mouseMoveHandler = function (e) {
13838
+ if (e.buttons === 1 || e.buttons === 2 || e.type === 'touchmove') {
13839
+ if (e.type === 'touchmove') {
13840
+ e.preventDefault();
13841
+ e.stopPropagation();
13842
+ }
13843
+ if (this.interval) {
13844
+ this.updateStrokeWithThrottle(e);
13845
+ }
13846
+ else {
13847
+ this.updateStroke(e);
13848
+ }
13849
+ }
13850
+ };
13851
+ SignatureBase.prototype.mouseUpHandler = function (e) {
13852
+ var args = { actionName: 'strokeUpdate' };
13853
+ if (e.type === 'touchstart') {
13854
+ e.preventDefault();
13855
+ e.stopPropagation();
13856
+ }
13857
+ this.endDraw();
13858
+ this.updateSnapCollection();
13859
+ this.unwireEvents(e.type);
13860
+ if (!this.isBlazor) {
13861
+ this.trigger('change', args);
13862
+ }
13863
+ else {
13864
+ this.dotnetRef.invokeMethodAsync('TriggerEventAsync', 'mouseUp');
13865
+ }
13866
+ this.signatureValue = this.snapColl[this.incStep];
13867
+ };
13868
+ SignatureBase.prototype.keyboardHandler = function (e) {
13869
+ var _this = this;
13870
+ var args = { fileName: 'Signature', type: 'Png', cancel: false };
13871
+ switch (e.key) {
13872
+ case 'Delete':
13873
+ this.clear();
13874
+ break;
13875
+ case (e.ctrlKey && 's'):
13876
+ if (!this.isBlazor) {
13877
+ this.trigger('beforeSave', args, function (observableSaveArgs) {
13878
+ if (!args.cancel) {
13879
+ _this.save(observableSaveArgs.type, observableSaveArgs.fileName);
13880
+ }
13881
+ });
13882
+ }
13883
+ else {
13884
+ this.dotnetRef.invokeMethodAsync('TriggerEventAsync', 'beforeSave');
13885
+ }
13886
+ e.preventDefault();
13887
+ e.stopImmediatePropagation();
13888
+ break;
13889
+ case (e.ctrlKey && 'z'):
13890
+ this.undo();
13891
+ break;
13892
+ case (e.ctrlKey && 'y'):
13893
+ this.redo();
13894
+ break;
13895
+ }
13896
+ };
13897
+ SignatureBase.prototype.resizeHandler = function () {
13898
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
13899
+ var proxy = this;
13900
+ this.canvasContext.canvas.width = this.element.offsetWidth;
13901
+ this.canvasContext.canvas.height = this.element.offsetHeight;
13902
+ this.canvasContext.scale(1, 1);
13903
+ var restoreImg = new Image();
13904
+ restoreImg.src = this.snapColl[this.incStep];
13905
+ restoreImg.onload = function () {
13906
+ proxy.canvasContext.clearRect(0, 0, proxy.element.width, proxy.element.height);
13907
+ proxy.canvasContext.drawImage(restoreImg, 0, 0, proxy.element.width, proxy.element.height);
13908
+ };
13909
+ };
13910
+ SignatureBase.prototype.beginStroke = function (e) {
13911
+ this.refresh();
13912
+ this.updateStroke(e);
13913
+ };
13914
+ SignatureBase.prototype.updateStroke = function (e) {
13915
+ var point = this.createPoint(e);
13916
+ this.addPoint(point);
13917
+ };
13918
+ SignatureBase.prototype.updateStrokeWithThrottle = function (args) {
13919
+ var now = Date.now();
13920
+ var remaining = this.interval - (now - this.previous);
13921
+ this.storedArgs = args;
13922
+ if (remaining <= 0 || remaining > this.interval) {
13923
+ if (this.timeout) {
13924
+ clearTimeout(this.timeout);
13925
+ this.timeout = null;
13926
+ }
13927
+ this.previous = now;
13928
+ this.updateStroke(this.storedArgs);
13929
+ if (!this.timeout) {
13930
+ this.storedArgs = null;
13931
+ }
13932
+ }
13933
+ else if (!this.timeout) {
13934
+ this.timeout = window.setTimeout(this.delay.bind(this), remaining);
13935
+ }
13936
+ };
13937
+ SignatureBase.prototype.delay = function () {
13938
+ this.previous = Date.now();
13939
+ this.timeout = null;
13940
+ this.updateStroke(this.storedArgs);
13941
+ if (!this.timeout) {
13942
+ this.storedArgs = null;
13943
+ }
13944
+ };
13945
+ SignatureBase.prototype.createPoint = function (e) {
13946
+ var rect = this.canvasContext.canvas.getBoundingClientRect();
13947
+ if (e.type === 'mousedown' || e.type === 'mousemove') {
13948
+ return this.point(e.clientX - rect.left, e.clientY - rect.top, new Date().getTime());
13949
+ }
13950
+ else {
13951
+ return this.point(e.touches[0].clientX - rect.left, e.touches[0].clientY - rect.top, new Date().getTime());
13952
+ }
13953
+ };
13954
+ /* Returns the current point corrdinates(x, y) and time.*/
13955
+ SignatureBase.prototype.point = function (pointX, pointY, time) {
13956
+ this.pointX = pointX;
13957
+ this.pointY = pointY;
13958
+ this.time = time || new Date().getTime();
13959
+ return { x: this.pointX, y: this.pointY, time: this.time };
13960
+ };
13961
+ SignatureBase.prototype.addPoint = function (point) {
13962
+ var points = this.pointColl;
13963
+ var controlPoint1;
13964
+ var controlPoint2;
13965
+ var lastPoint = points.length > 0 && points[points.length - 1];
13966
+ var isLastPointTooClose = lastPoint ? this.distanceTo(lastPoint) <= this.minDistance : false;
13967
+ if (!lastPoint || !(lastPoint && isLastPointTooClose)) {
13968
+ points.push(point);
13969
+ if (points.length > 2) {
13970
+ if (points.length === 3) {
13971
+ points.unshift(points[0]);
13972
+ }
13973
+ controlPoint1 = (this.calculateCurveControlPoints(points[0], points[1], points[2])).controlPoint2;
13974
+ controlPoint2 = (this.calculateCurveControlPoints(points[1], points[2], points[3])).controlPoint1;
13975
+ this.startPoint = points[1];
13976
+ this.controlPoint1 = controlPoint1;
13977
+ this.controlPoint2 = controlPoint2;
13978
+ this.endPoint = points[2];
13979
+ this.startDraw();
13980
+ points.shift();
13981
+ }
13982
+ }
13983
+ };
13984
+ SignatureBase.prototype.startDraw = function () {
13985
+ var velocity;
13986
+ velocity = this.pointVelocityCalc(this.startPoint);
13987
+ velocity = this.velocity * velocity + (1 - this.velocity) * this.lastVelocity;
13988
+ var newWidth = Math.max(this.maxStrokeWidth / (velocity + 1), this.minStrokeWidth);
13989
+ this.curveDraw(this.lastWidth, newWidth);
13990
+ this.lastVelocity = velocity;
13991
+ this.lastWidth = newWidth;
13992
+ };
13993
+ SignatureBase.prototype.endDraw = function () {
13994
+ var canDrawCurve = this.pointColl.length > 2;
13995
+ var point = this.pointColl[0];
13996
+ if (!canDrawCurve && point) {
13997
+ this.strokeDraw(point);
13998
+ }
13999
+ };
14000
+ /* Calculate the Bezier (x, y) coordinate of the curve. */
14001
+ SignatureBase.prototype.curveDraw = function (startWidth, endWidth) {
14002
+ var context = this.canvasContext;
14003
+ var width;
14004
+ var i;
14005
+ var t1;
14006
+ var t2;
14007
+ var t3;
14008
+ var u1;
14009
+ var u2;
14010
+ var u3;
14011
+ var x;
14012
+ var y;
14013
+ var widthValue = endWidth - startWidth;
14014
+ var bezierLength = this.bezierLengthCalc();
14015
+ var drawSteps = Math.ceil(bezierLength) * 2;
14016
+ context.beginPath();
14017
+ for (i = 0; i < drawSteps; i++) {
14018
+ t1 = i / drawSteps;
14019
+ t2 = t1 * t1;
14020
+ t3 = t2 * t1;
14021
+ u1 = 1 - t1;
14022
+ u2 = u1 * u1;
14023
+ u3 = u2 * u1;
14024
+ x = u3 * this.startPoint.x;
14025
+ x += 3 * u2 * t1 * this.controlPoint1.x;
14026
+ x += 3 * u1 * t2 * this.controlPoint2.x;
14027
+ x += t3 * this.endPoint.x;
14028
+ y = u3 * this.startPoint.y;
14029
+ y += 3 * u2 * t1 * this.controlPoint1.y;
14030
+ y += 3 * u1 * t2 * this.controlPoint2.y;
14031
+ y += t3 * this.endPoint.y;
14032
+ width = Math.min(startWidth + t3 * widthValue, this.maxStrokeWidth);
14033
+ this.arcDraw(x, y, width);
14034
+ }
14035
+ context.closePath();
14036
+ context.fill();
14037
+ this.isSignatureEmpty = false;
14038
+ };
14039
+ SignatureBase.prototype.strokeDraw = function (point) {
14040
+ var context = this.canvasContext;
14041
+ var pointSize = (this.minStrokeWidth + this.maxStrokeWidth) / 2;
14042
+ context.beginPath();
14043
+ this.arcDraw(point.x, point.y, pointSize);
14044
+ context.closePath();
14045
+ context.fill();
14046
+ this.isSignatureEmpty = false;
14047
+ };
14048
+ SignatureBase.prototype.arcDraw = function (x, y, size) {
14049
+ var context = this.canvasContext;
14050
+ context.moveTo(x, y);
14051
+ context.arc(x, y, size, 0, 2 * Math.PI, false);
14052
+ };
14053
+ /* Utility functions for Bezier algorithm*/
14054
+ SignatureBase.prototype.calculateCurveControlPoints = function (p1, p2, p3) {
14055
+ var dx1 = p1.x - p2.x;
14056
+ var dy1 = p1.y - p2.y;
14057
+ var dx2 = p2.x - p3.x;
14058
+ var dy2 = p2.y - p3.y;
14059
+ var m1 = { x: (p1.x + p2.x) / 2.0, y: (p1.y + p2.y) / 2.0 };
14060
+ var m2 = { x: (p2.x + p3.x) / 2.0, y: (p2.y + p3.y) / 2.0 };
14061
+ var l1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
14062
+ var l2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
14063
+ var dxm = (m1.x - m2.x);
14064
+ var dym = (m1.y - m2.y);
14065
+ var k = l2 / (l1 + l2);
14066
+ var cm = { x: m2.x + dxm * k, y: m2.y + dym * k };
14067
+ var tx = p2.x - cm.x;
14068
+ var ty = p2.y - cm.y;
14069
+ return {
14070
+ controlPoint1: this.point(m1.x + tx, m1.y + ty, 0),
14071
+ controlPoint2: this.point(m2.x + tx, m2.y + ty, 0)
14072
+ };
14073
+ };
14074
+ /* Returns approximated bezier length of the curuve.*/
14075
+ SignatureBase.prototype.bezierLengthCalc = function () {
14076
+ var steps = 10;
14077
+ var length = 0;
14078
+ var i;
14079
+ var t;
14080
+ var pointx1;
14081
+ var pointy1;
14082
+ var pointx2;
14083
+ var pointy2;
14084
+ var pointx3;
14085
+ var pointy3;
14086
+ for (i = 0; i <= steps; i++) {
14087
+ t = i / steps;
14088
+ pointx1 = this.bezierPointCalc(t, this.startPoint.x, this.controlPoint1.x, this.controlPoint2.x, this.endPoint.x);
14089
+ pointy1 = this.bezierPointCalc(t, this.startPoint.y, this.controlPoint1.y, this.controlPoint2.y, this.endPoint.y);
14090
+ if (i > 0) {
14091
+ pointx3 = pointx1 - pointx2;
14092
+ pointy3 = pointy1 - pointy2;
14093
+ length += Math.sqrt(pointx3 * pointx3 + pointy3 * pointy3);
14094
+ }
14095
+ pointx2 = pointx1;
14096
+ pointy2 = pointy1;
14097
+ }
14098
+ return length;
14099
+ };
14100
+ /* Calculate parametric value of x or y given t and the
14101
+ four point(startpoint, controlpoint1, controlpoint2, endpoint) coordinates of a cubic bezier curve.*/
14102
+ SignatureBase.prototype.bezierPointCalc = function (t, startpoint, cp1, cp2, endpoint) {
14103
+ return startpoint * (1.0 - t) * (1.0 - t) * (1.0 - t) + 3.0 * cp1 * (1.0 - t) * (1.0 - t) * t + 3.0 *
14104
+ cp2 * (1.0 - t) * t * t + endpoint * t * t * t;
14105
+ };
14106
+ /* Velocity between the current point and last point.*/
14107
+ SignatureBase.prototype.pointVelocityCalc = function (startPoint) {
14108
+ return (this.time !== startPoint.time) ? this.distanceTo(startPoint) / (this.time - startPoint.time) : 0;
14109
+ };
14110
+ /* Distance between the current point and last point.*/
14111
+ SignatureBase.prototype.distanceTo = function (start) {
14112
+ return Math.sqrt(Math.pow(this.pointX - start.x, 2) + Math.pow(this.pointY - start.y, 2));
14113
+ };
14114
+ SignatureBase.prototype.isRead = function (isRead) {
14115
+ if (isRead) {
14116
+ EventHandler.remove(this.canvasContext.canvas, 'mousedown touchstart', this.mouseDownHandler);
14117
+ }
14118
+ else if (!this.disabled) {
14119
+ EventHandler.add(this.canvasContext.canvas, 'mousedown touchstart', this.mouseDownHandler, this);
14120
+ }
14121
+ };
14122
+ SignatureBase.prototype.enableOrDisable = function (isDisable) {
14123
+ this.disabled = isDisable;
14124
+ if (isDisable) {
14125
+ this.reDraw('0.5');
14126
+ this.isRead(true);
14127
+ }
14128
+ else {
14129
+ this.reDraw('1');
14130
+ this.isRead(false);
14131
+ }
14132
+ };
14133
+ SignatureBase.prototype.reDraw = function (opacity) {
14134
+ var data = this.canvasContext.getImageData(0, 0, this.element.width, this.element.height);
14135
+ this.canvasContext.clearRect(0, 0, this.element.width, this.element.height);
14136
+ this.element.style.opacity = opacity;
14137
+ this.canvasContext.putImageData(data, 0, 0);
14138
+ };
14139
+ SignatureBase.prototype.updateSnapCollection = function (isClear) {
14140
+ if (isNullOrUndefined(this.incStep)) {
14141
+ this.incStep = -1;
14142
+ this.incStep++;
14143
+ this.snapColl = [];
14144
+ this.clearArray = [];
14145
+ }
14146
+ else {
14147
+ this.incStep++;
14148
+ }
14149
+ if (this.incStep < this.snapColl.length) {
14150
+ this.snapColl.length = this.incStep;
14151
+ }
14152
+ if (this.incStep > 0) {
14153
+ var canvasNew = this.createElement('canvas', { className: 'e-' + this.getModuleName() + '-wrapper' });
14154
+ var canvasContextNew = canvasNew.getContext('2d');
14155
+ canvasNew.width = this.canvasContext.canvas.width;
14156
+ canvasNew.height = this.canvasContext.canvas.height;
14157
+ canvasContextNew.drawImage(this.canvasContext.canvas, 0, 0, canvasNew.width, canvasNew.height);
14158
+ this.snapColl.push(canvasNew.toDataURL());
14159
+ }
14160
+ else {
14161
+ this.snapColl.push(this.canvasContext.canvas.toDataURL());
14162
+ }
14163
+ if (isClear) {
14164
+ this.clearArray.push(this.incStep);
14165
+ }
14166
+ };
14167
+ SignatureBase.prototype.setBackgroundImage = function (imageSrc) {
14168
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
14169
+ var proxy = this;
14170
+ var imageObj = new Image();
14171
+ imageObj.crossOrigin = 'anonymous';
14172
+ imageObj.src = imageSrc;
14173
+ imageObj.onload = function () {
14174
+ proxy.canvasContext.globalCompositeOperation = 'source-over';
14175
+ proxy.canvasContext.drawImage(imageObj, 0, 0, proxy.element.width, proxy.element.height);
14176
+ proxy.updateSnapCollection();
14177
+ proxy.saveBackground(true);
14178
+ };
14179
+ this.canvasContext.clearRect(0, 0, this.canvasContext.canvas.width, this.canvasContext.canvas.height);
14180
+ };
14181
+ SignatureBase.prototype.setBackgroundColor = function (color) {
14182
+ var canvasEle = this.canvasContext;
14183
+ canvasEle.strokeStyle = color;
14184
+ var i;
14185
+ var j;
14186
+ for (i = 1; i <= canvasEle.canvas.width; i++) {
14187
+ for (j = 1; j <= canvasEle.canvas.height; j++) {
14188
+ canvasEle.strokeRect(0, 0, i, j);
14189
+ }
14190
+ }
14191
+ this.updateSnapCollection();
14192
+ };
14193
+ SignatureBase.prototype.loadPersistedSignature = function () {
14194
+ if (isNullOrUndefined(this.signatureValue)) {
14195
+ return;
14196
+ }
14197
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
14198
+ var proxy = this;
14199
+ var lastImage = new Image();
14200
+ lastImage.src = this.signatureValue;
14201
+ lastImage.onload = function () {
14202
+ proxy.canvasContext.clearRect(0, 0, proxy.element.width, proxy.element.height);
14203
+ proxy.canvasContext.drawImage(lastImage, 0, 0);
14204
+ proxy.updateSnapCollection();
14205
+ };
14206
+ this.isSignatureEmpty = false;
14207
+ };
14208
+ /**
14209
+ * To get the signature as Blob.
14210
+ *
14211
+ * @param {string} url - specify the url/base 64 string to get blob of the signature.
14212
+ * @returns {Blob}.
14213
+ */
14214
+ SignatureBase.prototype.getBlob = function (url) {
14215
+ var arr = url.split(',');
14216
+ var type = arr[0].match(/:(.*?);/)[1];
14217
+ var bstr = atob(arr[1]);
14218
+ var n = bstr.length;
14219
+ var u8arr = new Uint8Array(n);
14220
+ while (n--) {
14221
+ u8arr[n] = bstr.charCodeAt(n);
14222
+ }
14223
+ return new Blob([u8arr], { type: type });
14224
+ };
14225
+ SignatureBase.prototype.download = function (blob, fileName) {
14226
+ var blobUrl = URL.createObjectURL(blob);
14227
+ var a = document.createElement('a');
14228
+ a.href = blobUrl;
14229
+ a.target = '_parent';
14230
+ a.download = fileName;
14231
+ (document.body || document.documentElement).appendChild(a);
14232
+ a.click();
14233
+ a.parentNode.removeChild(a);
14234
+ };
14235
+ /**
14236
+ * To refresh the signature.
14237
+ *
14238
+ * @private
14239
+ * @returns {void}.
14240
+ */
14241
+ SignatureBase.prototype.refresh = function () {
14242
+ this.pointColl = [];
14243
+ this.lastVelocity = 0;
14244
+ this.lastWidth = (this.minStrokeWidth + this.maxStrokeWidth) / 2;
14245
+ };
14246
+ /**
14247
+ * Erases all the signature strokes signed by user.
14248
+ *
14249
+ * @returns {void}.
14250
+ */
14251
+ SignatureBase.prototype.clear = function () {
14252
+ var args = { actionName: 'clear' };
14253
+ this.canvasContext.clearRect(0, 0, this.canvasContext.canvas.width, this.canvasContext.canvas.height);
14254
+ this.refresh();
14255
+ this.updateSnapCollection(true);
14256
+ this.isSignatureEmpty = true;
14257
+ if (!this.isBlazor) {
14258
+ this.trigger('change', args);
14259
+ }
14260
+ else {
14261
+ this.dotnetRef.invokeMethodAsync('TriggerEventAsync', 'Clear');
14262
+ }
14263
+ };
14264
+ /**
14265
+ * Undo the last user action.
14266
+ *
14267
+ * @returns {void}.
14268
+ */
14269
+ SignatureBase.prototype.undo = function () {
14270
+ var args = { actionName: 'undo' };
14271
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
14272
+ var proxy = this;
14273
+ if (this.incStep > 0) {
14274
+ this.incStep--;
14275
+ var undoImg_1 = new Image();
14276
+ undoImg_1.src = this.snapColl[this.incStep];
14277
+ undoImg_1.onload = function () {
14278
+ proxy.canvasContext.clearRect(0, 0, proxy.element.width, proxy.element.height);
14279
+ proxy.canvasContext.drawImage(undoImg_1, 0, 0, proxy.element.width, proxy.element.height);
14280
+ };
14281
+ }
14282
+ this.isClear();
14283
+ if (!this.isBlazor) {
14284
+ this.trigger('change', args);
14285
+ }
14286
+ else {
14287
+ this.dotnetRef.invokeMethodAsync('TriggerEventAsync', 'Undo');
14288
+ }
14289
+ };
14290
+ /**
14291
+ * Redo the last user action.
14292
+ *
14293
+ * @returns {void}.
14294
+ */
14295
+ SignatureBase.prototype.redo = function () {
14296
+ var args = { actionName: 'redo' };
14297
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
14298
+ var proxy = this;
14299
+ if (this.incStep < this.snapColl.length - 1) {
14300
+ this.incStep++;
14301
+ var redoImg_1 = new Image();
14302
+ redoImg_1.src = this.snapColl[this.incStep];
14303
+ redoImg_1.onload = function () {
14304
+ proxy.canvasContext.clearRect(0, 0, proxy.element.width, proxy.element.height);
14305
+ proxy.canvasContext.drawImage(redoImg_1, 0, 0, proxy.element.width, proxy.element.height);
14306
+ };
14307
+ }
14308
+ this.isClear();
14309
+ if (!this.isBlazor) {
14310
+ this.trigger('change', args);
14311
+ }
14312
+ else {
14313
+ this.dotnetRef.invokeMethodAsync('TriggerEventAsync', 'Redo');
14314
+ }
14315
+ };
14316
+ SignatureBase.prototype.isClear = function () {
14317
+ if (this.clearArray) {
14318
+ var empty = false;
14319
+ for (var i = 0; i < this.clearArray.length; i++) {
14320
+ if (this.clearArray[i] === this.incStep) {
14321
+ this.isSignatureEmpty = true;
14322
+ empty = true;
14323
+ }
14324
+ }
14325
+ if (!empty) {
14326
+ this.isSignatureEmpty = false;
14327
+ }
14328
+ }
14329
+ };
14330
+ /**
14331
+ * To check whether the signature is empty or not.
14332
+ *
14333
+ * @returns {boolean}.
14334
+ */
14335
+ SignatureBase.prototype.isEmpty = function () {
14336
+ return this.isSignatureEmpty;
14337
+ };
14338
+ /**
14339
+ * To check whether the undo collection is empty or not.
14340
+ *
14341
+ * @returns {boolean}.
14342
+ */
14343
+ SignatureBase.prototype.canUndo = function () {
14344
+ return this.incStep > 0;
14345
+ };
14346
+ /**
14347
+ * To check whether the redo collection is empty or not.
14348
+ *
14349
+ * @returns {boolean}.
14350
+ */
14351
+ SignatureBase.prototype.canRedo = function () {
14352
+ return this.incStep < this.snapColl.length - 1;
14353
+ };
14354
+ /**
14355
+ * To draw the signature based on the given text, with the font family and font size.
14356
+ *
14357
+ * @param {string} text - specify text to be drawn as signature.
14358
+ * @param {string} fontFamily - specify font family of a signature.
14359
+ * @param {number} fontSize - specify font size of a signature.
14360
+ *
14361
+ * @returns {void}.
14362
+ */
14363
+ SignatureBase.prototype.draw = function (text, fontFamily, fontSize) {
14364
+ this.canvasContext.clearRect(0, 0, this.canvasContext.canvas.width, this.canvasContext.canvas.height);
14365
+ fontFamily = fontFamily || 'Arial';
14366
+ fontSize = fontSize || 30;
14367
+ this.canvasContext.font = fontSize + 'px ' + fontFamily;
14368
+ this.canvasContext.textAlign = 'center';
14369
+ this.canvasContext.textBaseline = 'middle';
14370
+ this.canvasContext.fillText(text, this.element.width / 2, this.element.height / 2);
14371
+ this.updateSnapCollection();
14372
+ this.isSignatureEmpty = false;
14373
+ };
14374
+ /**
14375
+ * To load the signature with the given base 64 string, height and width.
14376
+ *
14377
+ * @param {string} signature - specify the url/base 64 string to be drawn as signature.
14378
+ * @param {number} width - specify the width of the loaded signature image.
14379
+ * @param {number} height - specify the height of the loaded signature image.
14380
+ * @returns {void}.
14381
+ */
14382
+ SignatureBase.prototype.load = function (signature, width, height) {
14383
+ height = height || this.element.height;
14384
+ width = width || this.element.width;
14385
+ this.canvasContext.clearRect(0, 0, this.canvasContext.canvas.width, this.canvasContext.canvas.height);
14386
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
14387
+ var proxy = this;
14388
+ var bitmapImage = new Image();
14389
+ bitmapImage.src = signature;
14390
+ bitmapImage.onload = function () {
14391
+ Promise.all([
14392
+ createImageBitmap(bitmapImage, 0, 0, width, height)
14393
+ ]).then(function (results) {
14394
+ var tempCanvas = document.createElement('canvas');
14395
+ tempCanvas.width = width;
14396
+ tempCanvas.height = height;
14397
+ tempCanvas.getContext('2d').drawImage(results[0], 0, 0);
14398
+ proxy.canvasContext.drawImage(tempCanvas, 0, 0, width, height, 0, 0, proxy.element.width, proxy.element.height);
14399
+ proxy.updateSnapCollection();
14400
+ });
14401
+ };
14402
+ this.isSignatureEmpty = false;
14403
+ };
14404
+ SignatureBase.prototype.saveBackground = function (savebg) {
14405
+ var imageSrc;
14406
+ if (savebg && this.backgroundImage) {
14407
+ imageSrc = this.snapColl[this.incStep - 1];
14408
+ }
14409
+ else {
14410
+ imageSrc = this.snapColl[this.incStep];
14411
+ }
14412
+ if (!savebg) {
14413
+ this.canvasContext.clearRect(0, 0, this.canvasContext.canvas.width, this.canvasContext.canvas.height);
14414
+ if (this.backgroundImage) {
14415
+ this.setBackgroundImage(this.backgroundImage);
14416
+ }
14417
+ else if (this.backgroundColor) {
14418
+ this.setBackgroundColor(this.backgroundColor);
14419
+ savebg = true;
14420
+ }
14421
+ }
14422
+ if (savebg) {
14423
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
14424
+ var proxy_1 = this;
14425
+ var imageObj_1 = new Image();
14426
+ imageObj_1.crossOrigin = 'anonymous';
14427
+ imageObj_1.src = imageSrc;
14428
+ imageObj_1.onload = function () {
14429
+ proxy_1.backgroundLoaded = true;
14430
+ proxy_1.canvasContext.globalCompositeOperation = 'source-over';
14431
+ proxy_1.canvasContext.drawImage(imageObj_1, 0, 0, proxy_1.element.width, proxy_1.element.height);
14432
+ proxy_1.save(proxy_1.fileType, proxy_1.fileName);
14433
+ };
14434
+ }
14435
+ };
14436
+ /**
14437
+ * To save the signature with the given file type and file name.
14438
+ *
14439
+ * @param {SignatureFileType} type - specify type of the file to be saved a signature.
14440
+ * @param {string} fileName - specify name of the file to be saved a signature.
14441
+ *
14442
+ * @returns {void}.
14443
+ */
14444
+ SignatureBase.prototype.save = function (type, fileName) {
14445
+ if (this.saveWithBackground && this.backgroundLoaded == null && (this.backgroundImage || this.backgroundColor)) {
14446
+ this.backgroundLoaded = false;
14447
+ this.fileType = type;
14448
+ this.fileName = fileName;
14449
+ this.saveBackground(false);
14450
+ }
14451
+ else if (type === 'Svg') {
14452
+ fileName = fileName || 'Signature';
14453
+ this.toSVG(fileName);
14454
+ }
14455
+ else if (type === 'Jpeg') {
14456
+ fileName = fileName || 'Signature';
14457
+ if (!this.saveWithBackground || this.saveWithBackground && !(this.backgroundImage || this.backgroundColor)) {
14458
+ this.toJPEG(fileName);
14459
+ }
14460
+ else {
14461
+ var dataURL = this.canvasContext.canvas.toDataURL('image/jpeg');
14462
+ this.download(this.getBlob(dataURL), fileName + '.' + 'jpeg');
14463
+ }
14464
+ }
14465
+ else {
14466
+ fileName = fileName || 'Signature';
14467
+ var dataURL = this.canvasContext.canvas.toDataURL('image/png');
14468
+ this.download(this.getBlob(dataURL), fileName + '.' + 'png');
14469
+ }
14470
+ if (this.saveWithBackground && this.backgroundLoaded) {
14471
+ this.resetSnap();
14472
+ }
14473
+ };
14474
+ SignatureBase.prototype.resetSnap = function () {
14475
+ this.canvasContext.clearRect(0, 0, this.canvasContext.canvas.width, this.canvasContext.canvas.height);
14476
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
14477
+ var proxy = this;
14478
+ var restoreObj = new Image();
14479
+ restoreObj.src = this.snapColl[this.incStep - 1];
14480
+ restoreObj.onload = function () {
14481
+ proxy.canvasContext.drawImage(restoreObj, 0, 0, proxy.element.width, proxy.element.height);
14482
+ proxy.updateSnapCollection();
14483
+ };
14484
+ this.backgroundLoaded = null;
14485
+ this.snapColl.pop();
14486
+ this.incStep--;
14487
+ this.snapColl.pop();
14488
+ this.incStep--;
14489
+ };
14490
+ SignatureBase.prototype.toJPEG = function (fileName) {
14491
+ var _this = this;
14492
+ var imageSrc = this.snapColl[this.incStep];
14493
+ this.setBackgroundColor('#ffffff');
14494
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
14495
+ var proxy = this;
14496
+ var imageObj = new Image();
14497
+ imageObj.crossOrigin = 'anonymous';
14498
+ imageObj.src = imageSrc;
14499
+ imageObj.onload = function () {
14500
+ proxy.canvasContext.globalCompositeOperation = 'source-over';
14501
+ proxy.canvasContext.drawImage(imageObj, 0, 0, proxy.element.width, proxy.element.height);
14502
+ var dataURL = proxy.canvasContext.canvas.toDataURL('image/jpeg');
14503
+ proxy.download(proxy.getBlob(dataURL), fileName + '.' + 'jpeg');
14504
+ proxy.canvasContext.clearRect(0, 0, proxy.canvasContext.canvas.width, proxy.canvasContext.canvas.height);
14505
+ _this.resizeHandler();
14506
+ };
14507
+ this.snapColl.pop();
14508
+ this.incStep--;
14509
+ };
14510
+ SignatureBase.prototype.toSVG = function (fileName) {
14511
+ var dataUrl = this.canvasContext.canvas.toDataURL();
14512
+ var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
14513
+ svg.setAttribute('width', this.canvasContext.canvas.width.toString());
14514
+ svg.setAttribute('height', this.canvasContext.canvas.height.toString());
14515
+ var XLinkNS = 'http://www.w3.org/1999/xlink';
14516
+ var img = document.createElementNS('http://www.w3.org/2000/svg', 'image');
14517
+ img.setAttributeNS(null, 'height', this.canvasContext.canvas.height.toString());
14518
+ img.setAttributeNS(null, 'width', this.canvasContext.canvas.width.toString());
14519
+ img.setAttributeNS(XLinkNS, 'xlink:href', dataUrl);
14520
+ svg.appendChild(img);
14521
+ var prefix = 'data:image/svg+xml;base64,';
14522
+ var header = '<svg' + ' xmlns="http://www.w3.org/2000/svg"' + ' xmlns:xlink="http://www.w3.org/1999/xlink"'
14523
+ + (" width=\"" + this.canvasContext.canvas.width + "\"") + (" height=\"" + this.canvasContext.canvas.height + "\"") + '>';
14524
+ var footer = '</svg>';
14525
+ var body = svg.innerHTML;
14526
+ var data = header + body + footer;
14527
+ var svgDataUrl = prefix + btoa(data);
14528
+ if (fileName == null) {
14529
+ return svgDataUrl;
14530
+ }
14531
+ else {
14532
+ this.download(this.getBlob(svgDataUrl), fileName + '.' + 'svg');
14533
+ return null;
14534
+ }
14535
+ };
14536
+ /**
14537
+ * To save the signature as Blob.
14538
+ *
14539
+ * @returns {Blob}.
14540
+ */
14541
+ SignatureBase.prototype.saveAsBlob = function () {
14542
+ return this.getBlob(this.canvasContext.canvas.toDataURL('image/png'));
14543
+ };
14544
+ /**
14545
+ * To get the signature as Base 64.
14546
+ *
14547
+ * @private
14548
+ * @param {SignatureFileType} type - Specifies the type of the image format.
14549
+ * @returns {string}.
14550
+ */
14551
+ SignatureBase.prototype.getSignature = function (type) {
14552
+ if (type === 'Jpeg') {
14553
+ var imgData = this.canvasContext.getImageData(0, 0, this.element.width, this.element.height);
14554
+ var data = imgData.data;
14555
+ for (var i = 0; i < data.length; i += 4) {
14556
+ if (data[i + 3] < 255) {
14557
+ data[i] = 255 - data[i];
14558
+ data[i + 1] = 255 - data[i + 1];
14559
+ data[i + 2] = 255 - data[i + 2];
14560
+ data[i + 3] = 255 - data[i + 3];
14561
+ }
14562
+ }
14563
+ this.canvasContext.putImageData(imgData, 0, 0);
14564
+ var dataURL = this.canvasContext.canvas.toDataURL('image/jpeg');
14565
+ this.resizeHandler();
14566
+ return dataURL;
14567
+ }
14568
+ else if (type === 'Svg') {
14569
+ return this.toSVG(null);
14570
+ }
14571
+ else {
14572
+ return this.canvasContext.canvas.toDataURL('image/png');
14573
+ }
14574
+ };
14575
+ /**
14576
+ * Get component name.
14577
+ *
14578
+ * @returns {string} - Module Name
14579
+ * @private
14580
+ */
14581
+ SignatureBase.prototype.getModuleName = function () {
14582
+ return 'signature';
14583
+ };
14584
+ /**
14585
+ * To get the properties to be maintained in the persisted state.
14586
+ *
14587
+ * @returns {string} - Persist data
14588
+ */
14589
+ SignatureBase.prototype.getPersistData = function () {
14590
+ this.signatureValue = this.snapColl[this.incStep];
14591
+ return this.addOnPersist(['signatureValue']);
14592
+ };
14593
+ /**
14594
+ * Removes the component from the DOM and detaches all its related event handlers.
14595
+ * Also it maintains the initial input element from the DOM.
14596
+ *
14597
+ * @method destroy
14598
+ * @returns {void}
14599
+ */
14600
+ SignatureBase.prototype.destroy = function () {
14601
+ this.unwireEvents(null);
14602
+ removeClass([this.element], 'e-' + this.getModuleName());
14603
+ this.element.removeAttribute('tabindex');
14604
+ this.pointColl = null;
14605
+ _super.prototype.destroy.call(this);
14606
+ };
14607
+ /**
14608
+ * Modified onPropertyChanged method for both blazor and EJ2 signature component.
14609
+ *
14610
+ * @private
14611
+ * @param {string} key - Specifies the property, which changed.
14612
+ * @param {string} value - Specifies the property value changed.
14613
+ * @returns {void}
14614
+ */
14615
+ SignatureBase.prototype.propertyChanged = function (key, value) {
14616
+ var canvasNew = this.canvasContext;
14617
+ switch (key) {
14618
+ case 'backgroundColor':
14619
+ canvasNew.canvas.style.backgroundColor = value;
14620
+ this.backgroundColor = value;
14621
+ break;
14622
+ case 'backgroundImage':
14623
+ canvasNew.canvas.style.backgroundImage = 'url(' + value + ')';
14624
+ this.backgroundImage = value;
14625
+ break;
14626
+ case 'strokeColor':
14627
+ canvasNew.fillStyle = value;
14628
+ this.strokeColor = value;
14629
+ break;
14630
+ case 'saveWithBackground':
14631
+ this.saveWithBackground = value;
14632
+ break;
14633
+ case 'maxStrokeWidth':
14634
+ this.maxStrokeWidth = value;
14635
+ break;
14636
+ case 'minStrokeWidth':
14637
+ this.minStrokeWidth = value;
14638
+ break;
14639
+ case 'velocity':
14640
+ this.velocity = value;
14641
+ break;
14642
+ case 'isReadOnly':
14643
+ this.isRead(value);
14644
+ break;
14645
+ case 'disabled':
14646
+ this.enableOrDisable(value);
14647
+ break;
14648
+ }
14649
+ };
14650
+ return SignatureBase;
14651
+ }(Component));
14652
+
14653
+ var __extends$7 = (undefined && undefined.__extends) || (function () {
14654
+ var extendStatics = function (d, b) {
14655
+ extendStatics = Object.setPrototypeOf ||
14656
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
14657
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
14658
+ return extendStatics(d, b);
14659
+ };
14660
+ return function (d, b) {
14661
+ extendStatics(d, b);
14662
+ function __() { this.constructor = d; }
14663
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14664
+ };
14665
+ })();
14666
+ var __decorate$7 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
14667
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14668
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
14669
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
14670
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
14671
+ };
14672
+ /**
14673
+ * The Signature component allows user to draw smooth signatures as vector outline of strokes using variable width bezier curve interpolation.
14674
+ * It allows to save signature as image.
14675
+ * You can use your finger, pen, or mouse on a tablet, touchscreen, etc., to draw your own signature on this Signature component.
14676
+ * Signature component is a user interface to draw the Signature or Text.
14677
+ * It provides supports for various Background color, Stroke color and Background Image.
14678
+ * ```html
14679
+ * <canvas id="signature"></canvas>
14680
+ * ```
14681
+ * ```typescript
14682
+ * <script>
14683
+ * let signatureObj: Signature = new Signature(null , "#signature");
14684
+ * </script>
14685
+ * ```
14686
+ */
14687
+ var Signature = /** @__PURE__ @class */ (function (_super) {
14688
+ __extends$7(Signature, _super);
14689
+ /**
14690
+ * Constructor for creating the widget.
14691
+ *
14692
+ * @param {SignatureModel} options - Specifies the Signature model.
14693
+ * @param {string | HTMLCanvasElement} element - Specifies the element.
14694
+ * @private
14695
+ */
14696
+ function Signature(options, element) {
14697
+ return _super.call(this, options, element) || this;
14698
+ }
14699
+ Signature.prototype.preRender = function () {
14700
+ // pre render code snippets
14701
+ };
14702
+ /**
14703
+ * To Initialize the component rendering
14704
+ *
14705
+ * @private
14706
+ * @returns {void}
14707
+ */
14708
+ Signature.prototype.render = function () {
14709
+ this.initialize();
14710
+ };
14711
+ Signature.prototype.initialize = function () {
14712
+ addClass([this.element], 'e-' + this.getModuleName());
14713
+ _super.prototype.initialize.call(this, this.element);
14714
+ if (this.enablePersistence) {
14715
+ this.loadPersistedSignature();
14716
+ }
14717
+ };
14718
+ /**
14719
+ * To get component name.
14720
+ *
14721
+ * @returns {string} - Module Name
14722
+ * @private
14723
+ */
14724
+ Signature.prototype.getModuleName = function () {
14725
+ return 'signature';
14726
+ };
14727
+ /**
14728
+ * To get the properties to be maintained in the persisted state.
14729
+ *
14730
+ * @returns {string} - Persist data
14731
+ */
14732
+ Signature.prototype.getPersistData = function () {
14733
+ return this.addOnPersist(['signatureValue']);
14734
+ };
14735
+ /**
14736
+ * Called internally if any of the property value changed.
14737
+ *
14738
+ * @param {SignatureModel} newProp - Specifies new properties
14739
+ * @param {SignatureModel} oldProp - Specifies old properties
14740
+ * @returns {void}
14741
+ * @private
14742
+ */
14743
+ Signature.prototype.onPropertyChanged = function (newProp, oldProp) {
14744
+ for (var _i = 0, _a = Object.keys(newProp); _i < _a.length; _i++) {
14745
+ var prop = _a[_i];
14746
+ switch (prop) {
14747
+ case 'backgroundColor':
14748
+ _super.prototype.propertyChanged.call(this, prop, newProp.backgroundColor);
14749
+ break;
14750
+ case 'backgroundImage':
14751
+ _super.prototype.propertyChanged.call(this, prop, newProp.backgroundImage);
14752
+ break;
14753
+ case 'strokeColor':
14754
+ if (newProp.strokeColor !== oldProp.strokeColor) {
14755
+ _super.prototype.propertyChanged.call(this, prop, newProp.strokeColor);
14756
+ }
14757
+ break;
14758
+ case 'saveWithBackground':
14759
+ _super.prototype.propertyChanged.call(this, prop, newProp.saveWithBackground);
14760
+ break;
14761
+ case 'isReadOnly':
14762
+ _super.prototype.propertyChanged.call(this, prop, newProp.isReadOnly);
14763
+ break;
14764
+ case 'disabled':
14765
+ _super.prototype.propertyChanged.call(this, prop, newProp.disabled);
14766
+ break;
14767
+ }
14768
+ }
14769
+ };
14770
+ __decorate$7([
14771
+ Property('')
14772
+ ], Signature.prototype, "backgroundColor", void 0);
14773
+ __decorate$7([
14774
+ Property('')
14775
+ ], Signature.prototype, "backgroundImage", void 0);
14776
+ __decorate$7([
14777
+ Property(false)
14778
+ ], Signature.prototype, "disabled", void 0);
14779
+ __decorate$7([
14780
+ Property(false)
14781
+ ], Signature.prototype, "isReadOnly", void 0);
14782
+ __decorate$7([
14783
+ Property(true)
14784
+ ], Signature.prototype, "saveWithBackground", void 0);
14785
+ __decorate$7([
14786
+ Property('#000000')
14787
+ ], Signature.prototype, "strokeColor", void 0);
14788
+ __decorate$7([
14789
+ Property(0.5)
14790
+ ], Signature.prototype, "minStrokeWidth", void 0);
14791
+ __decorate$7([
14792
+ Property(2)
14793
+ ], Signature.prototype, "maxStrokeWidth", void 0);
14794
+ __decorate$7([
14795
+ Property(0.7)
14796
+ ], Signature.prototype, "velocity", void 0);
14797
+ __decorate$7([
14798
+ Property('en-US')
14799
+ ], Signature.prototype, "locale", void 0);
14800
+ __decorate$7([
14801
+ Property(false)
14802
+ ], Signature.prototype, "enableRtl", void 0);
14803
+ __decorate$7([
14804
+ Property(false)
14805
+ ], Signature.prototype, "enablePersistence", void 0);
14806
+ __decorate$7([
14807
+ Event()
14808
+ ], Signature.prototype, "beforeSave", void 0);
14809
+ __decorate$7([
14810
+ Event()
14811
+ ], Signature.prototype, "change", void 0);
14812
+ __decorate$7([
14813
+ Event()
14814
+ ], Signature.prototype, "created", void 0);
14815
+ Signature = __decorate$7([
14816
+ NotifyPropertyChanges
14817
+ ], Signature);
14818
+ return Signature;
14819
+ }(SignatureBase));
14820
+
14821
+ /**
14822
+ * Signature modules
14823
+ */
14824
+
14825
+ /**
14826
+ * Signature base modules
14827
+ */
14828
+
13685
14829
  /**
13686
14830
  * NumericTextBox all modules
13687
14831
  */
13688
14832
 
13689
- export { NumericTextBox, regularExpressions, createMask, applyMask, wireEvents, unwireEvents, bindClearEvent, unstrippedValue, strippedValue, maskInputMouseDownHandler, maskInputMouseUpHandler, maskInputFocusHandler, triggerFocus, maskInputBlurHandler, maskInputDropHandler, mobileRemoveFunction, setMaskValue, setElementValue, maskInput, getVal, getMaskedVal, MaskUndo, MaskedTextBox, Input, TicksData, ColorRangeData, LimitData, TooltipData, Slider, regex, ErrorOption, FormValidator, FilesProp, ButtonsProps, AsyncSettings, Uploader, ColorPicker, TextBox };
14833
+ export { NumericTextBox, regularExpressions, createMask, applyMask, wireEvents, unwireEvents, bindClearEvent, unstrippedValue, strippedValue, maskInputMouseDownHandler, maskInputMouseUpHandler, maskInputFocusHandler, triggerFocus, maskInputBlurHandler, maskInputDropHandler, mobileRemoveFunction, setMaskValue, setElementValue, maskInput, getVal, getMaskedVal, MaskUndo, MaskedTextBox, Input, TicksData, ColorRangeData, LimitData, TooltipData, Slider, regex, ErrorOption, FormValidator, FilesProp, ButtonsProps, AsyncSettings, Uploader, ColorPicker, TextBox, Signature, SignatureBase };
13690
14834
  //# sourceMappingURL=ej2-inputs.es5.js.map