@syncfusion/ej2-inputs 19.3.47 → 19.4.38

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 (150) hide show
  1. package/.eslintrc.json +244 -0
  2. package/CHANGELOG.md +28 -0
  3. package/README.md +1 -1
  4. package/common.d.ts +4 -0
  5. package/common.js +4 -0
  6. package/dist/ej2-inputs.umd.min.js +2 -2
  7. package/dist/ej2-inputs.umd.min.js.map +1 -1
  8. package/dist/es6/ej2-inputs.es2015.js +1124 -12
  9. package/dist/es6/ej2-inputs.es2015.js.map +1 -1
  10. package/dist/es6/ej2-inputs.es5.js +1158 -11
  11. package/dist/es6/ej2-inputs.es5.js.map +1 -1
  12. package/dist/global/ej2-inputs.min.js +2 -2
  13. package/dist/global/ej2-inputs.min.js.map +1 -1
  14. package/dist/global/index.d.ts +1 -1
  15. package/package.json +9 -9
  16. package/signature.d.ts +4 -0
  17. package/signature.js +4 -0
  18. package/src/color-picker/color-picker-model.d.ts +7 -0
  19. package/src/color-picker/color-picker.d.ts +6 -0
  20. package/src/color-picker/color-picker.js +10 -1
  21. package/src/common/index.d.ts +4 -0
  22. package/src/common/index.js +4 -0
  23. package/src/common/signature-base.d.ts +320 -0
  24. package/src/common/signature-base.js +946 -0
  25. package/src/index.d.ts +2 -0
  26. package/src/index.js +2 -0
  27. package/src/input/input.js +10 -6
  28. package/src/maskedtextbox/base/mask-base.js +1 -1
  29. package/src/numerictextbox/numerictextbox.js +6 -1
  30. package/src/signature/index.d.ts +5 -0
  31. package/src/signature/index.js +4 -0
  32. package/src/signature/signature-model.d.ts +131 -0
  33. package/src/signature/signature.d.ts +167 -0
  34. package/src/signature/signature.js +171 -0
  35. package/src/slider/slider.d.ts +1 -0
  36. package/src/slider/slider.js +9 -0
  37. package/src/textbox/textbox.js +1 -1
  38. package/styles/bootstrap-dark.css +23 -16
  39. package/styles/bootstrap-dark.scss +1 -0
  40. package/styles/bootstrap.css +23 -16
  41. package/styles/bootstrap.scss +1 -0
  42. package/styles/bootstrap4.css +23 -16
  43. package/styles/bootstrap4.scss +1 -0
  44. package/styles/bootstrap5-dark.css +27 -42
  45. package/styles/bootstrap5-dark.scss +1 -0
  46. package/styles/bootstrap5.css +27 -42
  47. package/styles/bootstrap5.scss +1 -0
  48. package/styles/color-picker/_fabric-dark-definition.scss +1 -1
  49. package/styles/color-picker/_fluent-definition.scss +134 -0
  50. package/styles/color-picker/_layout.scss +5 -5
  51. package/styles/color-picker/_theme.scss +1 -15
  52. package/styles/color-picker/bootstrap5-dark.css +3 -21
  53. package/styles/color-picker/bootstrap5.css +3 -21
  54. package/styles/color-picker/fabric-dark.css +3 -3
  55. package/styles/color-picker/icons/_fluent.scss +10 -0
  56. package/styles/fabric-dark.css +26 -19
  57. package/styles/fabric-dark.scss +1 -0
  58. package/styles/fabric.css +23 -16
  59. package/styles/fabric.scss +1 -0
  60. package/styles/highcontrast-light.css +23 -16
  61. package/styles/highcontrast-light.scss +1 -0
  62. package/styles/highcontrast.css +23 -16
  63. package/styles/highcontrast.scss +1 -0
  64. package/styles/input/_fluent-definition.scss +321 -0
  65. package/styles/input/_layout.scss +138 -37
  66. package/styles/input/_theme.scss +42 -24
  67. package/styles/input/bootstrap-dark.css +13 -16
  68. package/styles/input/bootstrap.css +13 -16
  69. package/styles/input/bootstrap4.css +13 -16
  70. package/styles/input/bootstrap5-dark.css +13 -16
  71. package/styles/input/bootstrap5.css +13 -16
  72. package/styles/input/fabric-dark.css +13 -16
  73. package/styles/input/fabric.css +13 -16
  74. package/styles/input/highcontrast-light.css +13 -16
  75. package/styles/input/highcontrast.css +13 -16
  76. package/styles/input/icons/_fluent.scss +17 -0
  77. package/styles/input/material-dark.css +13 -16
  78. package/styles/input/material.css +13 -16
  79. package/styles/input/tailwind-dark.css +13 -16
  80. package/styles/input/tailwind.css +13 -16
  81. package/styles/maskedtextbox/_fluent-definition.scss +7 -0
  82. package/styles/maskedtextbox/_theme.scss +2 -2
  83. package/styles/material-dark.css +23 -16
  84. package/styles/material-dark.scss +1 -0
  85. package/styles/material.css +23 -16
  86. package/styles/material.scss +1 -0
  87. package/styles/numerictextbox/_fluent-definition.scss +5 -0
  88. package/styles/numerictextbox/_theme.scss +18 -0
  89. package/styles/numerictextbox/icons/_fluent.scss +12 -0
  90. package/styles/signature/_all.scss +2 -0
  91. package/styles/signature/_bootstrap-dark-definition.scss +3 -0
  92. package/styles/signature/_bootstrap-definition.scss +3 -0
  93. package/styles/signature/_bootstrap4-definition.scss +3 -0
  94. package/styles/signature/_bootstrap5-dark-definition.scss +1 -0
  95. package/styles/signature/_bootstrap5-definition.scss +3 -0
  96. package/styles/signature/_fabric-dark-definition.scss +3 -0
  97. package/styles/signature/_fabric-definition.scss +3 -0
  98. package/styles/signature/_fluent-definition.scss +3 -0
  99. package/styles/signature/_highcontrast-definition.scss +3 -0
  100. package/styles/signature/_highcontrast-light-definition.scss +3 -0
  101. package/styles/signature/_layout.scss +5 -0
  102. package/styles/signature/_material-dark-definition.scss +3 -0
  103. package/styles/signature/_material-definition.scss +3 -0
  104. package/styles/signature/_tailwind-dark-definition.scss +1 -0
  105. package/styles/signature/_tailwind-definition.scss +3 -0
  106. package/styles/signature/_theme.scss +7 -0
  107. package/styles/signature/bootstrap-dark.css +9 -0
  108. package/styles/signature/bootstrap-dark.scss +3 -0
  109. package/styles/signature/bootstrap.css +9 -0
  110. package/styles/signature/bootstrap.scss +3 -0
  111. package/styles/signature/bootstrap4.css +9 -0
  112. package/styles/signature/bootstrap4.scss +3 -0
  113. package/styles/signature/bootstrap5-dark.css +9 -0
  114. package/styles/signature/bootstrap5-dark.scss +3 -0
  115. package/styles/signature/bootstrap5.css +9 -0
  116. package/styles/signature/bootstrap5.scss +3 -0
  117. package/styles/signature/fabric-dark.css +9 -0
  118. package/styles/signature/fabric-dark.scss +3 -0
  119. package/styles/signature/fabric.css +9 -0
  120. package/styles/signature/fabric.scss +3 -0
  121. package/styles/signature/highcontrast-light.css +9 -0
  122. package/styles/signature/highcontrast-light.scss +3 -0
  123. package/styles/signature/highcontrast.css +9 -0
  124. package/styles/signature/highcontrast.scss +3 -0
  125. package/styles/signature/material-dark.css +10 -0
  126. package/styles/signature/material-dark.scss +3 -0
  127. package/styles/signature/material.css +10 -0
  128. package/styles/signature/material.scss +3 -0
  129. package/styles/signature/tailwind-dark.css +10 -0
  130. package/styles/signature/tailwind-dark.scss +3 -0
  131. package/styles/signature/tailwind.css +10 -0
  132. package/styles/signature/tailwind.scss +3 -0
  133. package/styles/slider/_bootstrap5-definition.scss +2 -2
  134. package/styles/slider/_fluent-definition.scss +94 -0
  135. package/styles/slider/_layout.scss +7 -2
  136. package/styles/slider/_tailwind-definition.scss +2 -2
  137. package/styles/slider/bootstrap5-dark.css +1 -5
  138. package/styles/slider/bootstrap5.css +1 -5
  139. package/styles/slider/tailwind-dark.css +1 -5
  140. package/styles/slider/tailwind.css +1 -5
  141. package/styles/tailwind-dark.css +25 -21
  142. package/styles/tailwind-dark.scss +1 -0
  143. package/styles/tailwind.css +25 -21
  144. package/styles/tailwind.scss +1 -0
  145. package/styles/textbox/_fluent-definition.scss +0 -0
  146. package/styles/uploader/_fluent-definition.scss +234 -0
  147. package/styles/uploader/_layout.scss +99 -8
  148. package/styles/uploader/_theme.scss +5 -2
  149. package/styles/uploader/icons/_fluent.scss +34 -0
  150. package/tslint.json +111 -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', (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', (event) => {
@@ -237,7 +237,7 @@ var Input;
237
237
  addClass([button], CLASSNAMES.CLEARICONHIDE);
238
238
  }
239
239
  }
240
- function updateLabelState(value, label) {
240
+ function updateLabelState(value, label, element = null) {
241
241
  if (value) {
242
242
  addClass([label], CLASSNAMES.LABELTOP);
243
243
  if (label.classList.contains(CLASSNAMES.LABELBOTTOM)) {
@@ -245,10 +245,13 @@ var Input;
245
245
  }
246
246
  }
247
247
  else {
248
- if (label.classList.contains(CLASSNAMES.LABELTOP)) {
249
- removeClass([label], CLASSNAMES.LABELTOP);
248
+ const isNotFocused = element != null ? element !== document.activeElement : true;
249
+ if (isNotFocused) {
250
+ if (label.classList.contains(CLASSNAMES.LABELTOP)) {
251
+ removeClass([label], CLASSNAMES.LABELTOP);
252
+ }
253
+ addClass([label], CLASSNAMES.LABELBOTTOM);
250
254
  }
251
- addClass([label], CLASSNAMES.LABELBOTTOM);
252
255
  }
253
256
  }
254
257
  function getParentNode(element) {
@@ -317,7 +320,7 @@ var Input;
317
320
  const parent = getParentNode(element);
318
321
  if (parent.classList.contains(CLASSNAMES.FLOATINPUT) && floatLabelType === 'Auto') {
319
322
  const label = getParentNode(element).getElementsByClassName('e-float-text')[0];
320
- updateLabelState(element.value, label);
323
+ updateLabelState(element.value, label, element);
321
324
  }
322
325
  }
323
326
  /**
@@ -1211,7 +1214,7 @@ let NumericTextBox = class NumericTextBox extends Component {
1211
1214
  }
1212
1215
  resetHandler(e) {
1213
1216
  e.preventDefault();
1214
- if (!(this.inputWrapper.clearButton.classList.contains('e-clear-icon-hide'))) {
1217
+ if (!(this.inputWrapper.clearButton.classList.contains('e-clear-icon-hide')) || this.inputWrapper.container.classList.contains('e-static-clear')) {
1215
1218
  this.clear(e);
1216
1219
  }
1217
1220
  this.isInteract = true;
@@ -1453,8 +1456,13 @@ let NumericTextBox = class NumericTextBox extends Component {
1453
1456
  this.preventChange = true;
1454
1457
  }
1455
1458
  if (this.isVue) {
1456
- const current = this.instance.getNumberParser({ format: 'n' })(this.element.value);
1459
+ let current = this.instance.getNumberParser({ format: 'n' })(this.element.value);
1457
1460
  const previous = this.instance.getNumberParser({ format: 'n' })(this.elementPrevValue);
1461
+ //EJ2-54963-if type "." or ".0" or "-.0" it converts to "0" automatically when binding v-model
1462
+ const nonZeroRegex = new RegExp('[^1-9]+$');
1463
+ if (nonZeroRegex.test(this.element.value)) {
1464
+ current = this.value;
1465
+ }
1458
1466
  const eventArgs = {
1459
1467
  event: event,
1460
1468
  value: (current === null || isNaN(current) ? null : current),
@@ -2306,7 +2314,7 @@ function bindClearEvent() {
2306
2314
  }
2307
2315
  function resetHandler(e) {
2308
2316
  e.preventDefault();
2309
- if (!this.inputObj.clearButton.classList.contains('e-clear-icon-hide')) {
2317
+ if (!this.inputObj.clearButton.classList.contains('e-clear-icon-hide') || (this.inputObj.container.classList.contains('e-static-clear'))) {
2310
2318
  clear.call(this, e);
2311
2319
  this.value = '';
2312
2320
  }
@@ -4333,9 +4341,11 @@ let Slider = class Slider extends Component {
4333
4341
  this.sliderBarClick(e);
4334
4342
  if (e.currentTarget === this.firstHandle) {
4335
4343
  this.firstHandle.classList.add(classNames.sliderHandleFocused);
4344
+ this.firstHandle.classList.add(classNames.sliderTabHandle);
4336
4345
  }
4337
4346
  else {
4338
4347
  this.secondHandle.classList.add(classNames.sliderHandleFocused);
4348
+ this.secondHandle.classList.add(classNames.sliderTabHandle);
4339
4349
  }
4340
4350
  EventHandler.add(document, 'mousemove touchmove', this.sliderBarMove, this);
4341
4351
  EventHandler.add(document, 'mouseup touchend', this.sliderBarUp, this);
@@ -4746,6 +4756,11 @@ let Slider = class Slider extends Component {
4746
4756
  this.getHandle().classList.add('e-large-thumb-size');
4747
4757
  }
4748
4758
  }
4759
+ focusHandle() {
4760
+ if (!this.getHandle().classList.contains(classNames.sliderTabHandle)) {
4761
+ this.getHandle().classList.add(classNames.sliderTabHandle);
4762
+ }
4763
+ }
4749
4764
  repeatHandlerUp(e) {
4750
4765
  this.changeEvent('changed', e);
4751
4766
  this.closeTooltip();
@@ -5136,6 +5151,7 @@ let Slider = class Slider extends Component {
5136
5151
  }
5137
5152
  this.tooltipToggle(this.getHandle());
5138
5153
  this.getHandle().focus();
5154
+ this.focusHandle();
5139
5155
  if (args.currentTarget.classList.contains(classNames.firstButton)) {
5140
5156
  EventHandler.add(this.firstBtn, 'mouseup touchend', this.buttonUp, this);
5141
5157
  }
@@ -6076,6 +6092,7 @@ let Slider = class Slider extends Component {
6076
6092
  event.preventDefault();
6077
6093
  this.focusSliderElement();
6078
6094
  this.sliderBarClick(event);
6095
+ this.focusHandle();
6079
6096
  }
6080
6097
  wireEvents() {
6081
6098
  this.onresize = this.reposition.bind(this);
@@ -10990,6 +11007,7 @@ let ColorPicker = class ColorPicker extends Component {
10990
11007
  target: this.container,
10991
11008
  disabled: this.disabled,
10992
11009
  enableRtl: this.enableRtl,
11010
+ createPopupOnClick: this.createPopupOnClick,
10993
11011
  open: this.onOpen.bind(this),
10994
11012
  click: () => {
10995
11013
  this.trigger('change', {
@@ -12128,7 +12146,12 @@ let ColorPicker = class ColorPicker extends Component {
12128
12146
  if (!this.showButtons && !isKey) {
12129
12147
  this.trigger('change', { currentValue: { hex: hex, rgba: rgba },
12130
12148
  previousValue: { hex: this.value.slice(0, 7), rgba: this.convertToRgbString(this.hexToRgb(this.value)) }, value: cValue });
12131
- this.setProperties({ 'value': cValue }, true);
12149
+ if (this.enableOpacity) {
12150
+ this.setProperties({ 'value': cValue }, true);
12151
+ }
12152
+ else {
12153
+ this.setProperties({ 'value': hex }, true);
12154
+ }
12132
12155
  this.element.value = hex ? hex : '#000000';
12133
12156
  }
12134
12157
  else {
@@ -12644,6 +12667,9 @@ __decorate$5([
12644
12667
  __decorate$5([
12645
12668
  Property(true)
12646
12669
  ], ColorPicker.prototype, "enableOpacity", void 0);
12670
+ __decorate$5([
12671
+ Property(false)
12672
+ ], ColorPicker.prototype, "createPopupOnClick", void 0);
12647
12673
  __decorate$5([
12648
12674
  Event()
12649
12675
  ], ColorPicker.prototype, "select", void 0);
@@ -13161,7 +13187,7 @@ let TextBox = class TextBox extends Component {
13161
13187
  }
13162
13188
  resetInputHandler(event) {
13163
13189
  event.preventDefault();
13164
- if (!(this.textboxWrapper.clearButton.classList.contains(HIDE_CLEAR))) {
13190
+ if (!(this.textboxWrapper.clearButton.classList.contains(HIDE_CLEAR)) || this.textboxWrapper.container.classList.contains('e-static-clear')) {
13165
13191
  Input.setValue('', this.respectiveElement, this.floatLabelType, this.showClearButton);
13166
13192
  if (this.isHiddenInput) {
13167
13193
  this.element.value = this.respectiveElement.value;
@@ -13389,9 +13415,1095 @@ TextBox = __decorate$6([
13389
13415
  * Uploader modules
13390
13416
  */
13391
13417
 
13418
+ class SignatureBase extends Component {
13419
+ constructor() {
13420
+ super(...arguments);
13421
+ /* minDistance(distance between the two point) was calaculated for smoothness.*/
13422
+ this.minDistance = 5;
13423
+ this.previous = 0;
13424
+ /* interval handles for the smoothness in the mouse move event.*/
13425
+ this.interval = 30;
13426
+ this.timeout = null;
13427
+ this.isSignatureEmpty = true;
13428
+ this.backgroundLoaded = null;
13429
+ this.clearArray = [];
13430
+ this.isBlazor = false;
13431
+ }
13432
+ /**
13433
+ * To Initialize the component rendering
13434
+ *
13435
+ * @private
13436
+ * @param {HTMLCanvasElement} element - Specifies the canvas element.
13437
+ * @param {parameter} parameter - Specifies only for the blazor parameter.
13438
+ * @param {BlazorDotnetObject} dotnetRef - Specifies for blazor client to server communication.
13439
+ * @returns {void}
13440
+ */
13441
+ initialize(element, parameter, dotnetRef) {
13442
+ this.element = element;
13443
+ this.canvasContext = this.element.getContext('2d');
13444
+ this.canvasContext.canvas.tabIndex = 0;
13445
+ if (parameter) {
13446
+ this.setBlazorParameter(parameter);
13447
+ this.dotnetRef = dotnetRef;
13448
+ }
13449
+ this.setHTMLProperties();
13450
+ if (isNullOrUndefined(this.signatureValue)) {
13451
+ this.updateSnapCollection(true);
13452
+ }
13453
+ this.wireEvents();
13454
+ this.isSignatureEmpty = true;
13455
+ if (!this.isBlazor) {
13456
+ this.trigger('created', null);
13457
+ }
13458
+ }
13459
+ setBlazorParameter(parameter) {
13460
+ this.isBlazor = true;
13461
+ this.backgroundColor = parameter.backgroundColor;
13462
+ this.backgroundImage = parameter.backgroundImage;
13463
+ this.disabled = parameter.disabled;
13464
+ this.isReadOnly = parameter.isReadOnly;
13465
+ this.maxStrokeWidth = parameter.maxStrokeWidth || 2;
13466
+ this.minStrokeWidth = parameter.minStrokeWidth || 0.5;
13467
+ this.velocity = parameter.velocity || 0.7;
13468
+ this.strokeColor = parameter.strokeColor || '#000000';
13469
+ this.saveWithBackground = parameter.saveWithBackground;
13470
+ this.interval = 30;
13471
+ this.previous = 0;
13472
+ this.minDistance = 5;
13473
+ this.signatureValue = parameter.signatureValue;
13474
+ if (this.signatureValue) {
13475
+ this.loadPersistedSignature();
13476
+ }
13477
+ }
13478
+ wireEvents() {
13479
+ if (isNullOrUndefined(this.pointColl) && !this.isReadOnly && !this.disabled) {
13480
+ EventHandler.add(this.canvasContext.canvas, 'mousedown touchstart', this.mouseDownHandler, this);
13481
+ EventHandler.add(this.canvasContext.canvas, 'keydown', this.keyboardHandler, this);
13482
+ window.addEventListener('resize', this.resizeHandler.bind(this));
13483
+ }
13484
+ else if (this.pointColl) {
13485
+ EventHandler.add(this.canvasContext.canvas, 'mousemove touchmove', this.mouseMoveHandler, this);
13486
+ EventHandler.add(this.canvasContext.canvas, 'mouseup touchend', this.mouseUpHandler, this);
13487
+ EventHandler.add(document, 'mouseup', this.mouseUpHandler, this);
13488
+ }
13489
+ }
13490
+ unwireEvents(type) {
13491
+ if (type === 'mouseup' || type === 'touchend') {
13492
+ EventHandler.remove(this.canvasContext.canvas, 'mousemove touchmove', this.mouseMoveHandler);
13493
+ EventHandler.remove(this.canvasContext.canvas, 'mouseup touchend', this.mouseUpHandler);
13494
+ EventHandler.remove(document, 'mouseup', this.mouseUpHandler);
13495
+ }
13496
+ else {
13497
+ EventHandler.remove(this.canvasContext.canvas, 'mousedown touchstart', this.mouseDownHandler);
13498
+ EventHandler.remove(this.canvasContext.canvas, 'mousemove touchmove', this.mouseMoveHandler);
13499
+ EventHandler.remove(this.canvasContext.canvas, 'mouseup touchend', this.mouseUpHandler);
13500
+ EventHandler.remove(document, 'mouseup', this.mouseUpHandler);
13501
+ EventHandler.remove(this.canvasContext.canvas, 'keydown', this.keyboardHandler);
13502
+ window.removeEventListener('resize', this.resizeHandler);
13503
+ }
13504
+ }
13505
+ setHTMLProperties() {
13506
+ if (this.element.height === 150) {
13507
+ this.element.height = this.element.offsetHeight;
13508
+ }
13509
+ if (this.element.width === 300) {
13510
+ this.element.width = this.element.offsetWidth;
13511
+ }
13512
+ this.canvasContext.scale(1, 1);
13513
+ this.canvasContext.fillStyle = this.strokeColor;
13514
+ if (this.backgroundImage) {
13515
+ this.canvasContext.canvas.style.backgroundImage = 'url(' + this.backgroundImage + ')';
13516
+ }
13517
+ else if (this.backgroundColor) {
13518
+ this.canvasContext.canvas.style.backgroundColor = this.backgroundColor;
13519
+ }
13520
+ }
13521
+ mouseDownHandler(e) {
13522
+ if (e.buttons === 1 || e.buttons === 2 || e.type === 'touchstart') {
13523
+ if (e.type === 'touchstart') {
13524
+ e.preventDefault();
13525
+ e.stopPropagation();
13526
+ }
13527
+ this.beginStroke(e);
13528
+ this.wireEvents();
13529
+ }
13530
+ }
13531
+ mouseMoveHandler(e) {
13532
+ if (e.buttons === 1 || e.buttons === 2 || e.type === 'touchmove') {
13533
+ if (e.type === 'touchmove') {
13534
+ e.preventDefault();
13535
+ e.stopPropagation();
13536
+ }
13537
+ if (this.interval) {
13538
+ this.updateStrokeWithThrottle(e);
13539
+ }
13540
+ else {
13541
+ this.updateStroke(e);
13542
+ }
13543
+ }
13544
+ }
13545
+ mouseUpHandler(e) {
13546
+ const args = { actionName: 'strokeUpdate' };
13547
+ if (e.type === 'touchstart') {
13548
+ e.preventDefault();
13549
+ e.stopPropagation();
13550
+ }
13551
+ this.endDraw();
13552
+ this.updateSnapCollection();
13553
+ this.unwireEvents(e.type);
13554
+ if (!this.isBlazor) {
13555
+ this.trigger('change', args);
13556
+ }
13557
+ else {
13558
+ this.dotnetRef.invokeMethodAsync('TriggerEventAsync', 'mouseUp');
13559
+ }
13560
+ this.signatureValue = this.snapColl[this.incStep];
13561
+ }
13562
+ keyboardHandler(e) {
13563
+ const args = { fileName: 'Signature', type: 'Png', cancel: false };
13564
+ switch (e.key) {
13565
+ case 'Delete':
13566
+ this.clear();
13567
+ break;
13568
+ case (e.ctrlKey && 's'):
13569
+ if (!this.isBlazor) {
13570
+ this.trigger('beforeSave', args, (observableSaveArgs) => {
13571
+ if (!args.cancel) {
13572
+ this.save(observableSaveArgs.type, observableSaveArgs.fileName);
13573
+ }
13574
+ });
13575
+ }
13576
+ else {
13577
+ this.dotnetRef.invokeMethodAsync('TriggerEventAsync', 'beforeSave');
13578
+ }
13579
+ e.preventDefault();
13580
+ e.stopImmediatePropagation();
13581
+ break;
13582
+ case (e.ctrlKey && 'z'):
13583
+ this.undo();
13584
+ break;
13585
+ case (e.ctrlKey && 'y'):
13586
+ this.redo();
13587
+ break;
13588
+ }
13589
+ }
13590
+ resizeHandler() {
13591
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
13592
+ const proxy = this;
13593
+ this.canvasContext.canvas.width = this.element.offsetWidth;
13594
+ this.canvasContext.canvas.height = this.element.offsetHeight;
13595
+ this.canvasContext.scale(1, 1);
13596
+ const restoreImg = new Image();
13597
+ restoreImg.src = this.snapColl[this.incStep];
13598
+ restoreImg.onload = () => {
13599
+ proxy.canvasContext.clearRect(0, 0, proxy.element.width, proxy.element.height);
13600
+ proxy.canvasContext.drawImage(restoreImg, 0, 0, proxy.element.width, proxy.element.height);
13601
+ };
13602
+ }
13603
+ beginStroke(e) {
13604
+ this.refresh();
13605
+ this.updateStroke(e);
13606
+ }
13607
+ updateStroke(e) {
13608
+ const point = this.createPoint(e);
13609
+ this.addPoint(point);
13610
+ }
13611
+ updateStrokeWithThrottle(args) {
13612
+ const now = Date.now();
13613
+ const remaining = this.interval - (now - this.previous);
13614
+ this.storedArgs = args;
13615
+ if (remaining <= 0 || remaining > this.interval) {
13616
+ if (this.timeout) {
13617
+ clearTimeout(this.timeout);
13618
+ this.timeout = null;
13619
+ }
13620
+ this.previous = now;
13621
+ this.updateStroke(this.storedArgs);
13622
+ if (!this.timeout) {
13623
+ this.storedArgs = null;
13624
+ }
13625
+ }
13626
+ else if (!this.timeout) {
13627
+ this.timeout = window.setTimeout(this.delay.bind(this), remaining);
13628
+ }
13629
+ }
13630
+ delay() {
13631
+ this.previous = Date.now();
13632
+ this.timeout = null;
13633
+ this.updateStroke(this.storedArgs);
13634
+ if (!this.timeout) {
13635
+ this.storedArgs = null;
13636
+ }
13637
+ }
13638
+ createPoint(e) {
13639
+ const rect = this.canvasContext.canvas.getBoundingClientRect();
13640
+ if (e.type === 'mousedown' || e.type === 'mousemove') {
13641
+ return this.point(e.clientX - rect.left, e.clientY - rect.top, new Date().getTime());
13642
+ }
13643
+ else {
13644
+ return this.point(e.touches[0].clientX - rect.left, e.touches[0].clientY - rect.top, new Date().getTime());
13645
+ }
13646
+ }
13647
+ /* Returns the current point corrdinates(x, y) and time.*/
13648
+ point(pointX, pointY, time) {
13649
+ this.pointX = pointX;
13650
+ this.pointY = pointY;
13651
+ this.time = time || new Date().getTime();
13652
+ return { x: this.pointX, y: this.pointY, time: this.time };
13653
+ }
13654
+ addPoint(point) {
13655
+ const points = this.pointColl;
13656
+ let controlPoint1;
13657
+ let controlPoint2;
13658
+ const lastPoint = points.length > 0 && points[points.length - 1];
13659
+ const isLastPointTooClose = lastPoint ? this.distanceTo(lastPoint) <= this.minDistance : false;
13660
+ if (!lastPoint || !(lastPoint && isLastPointTooClose)) {
13661
+ points.push(point);
13662
+ if (points.length > 2) {
13663
+ if (points.length === 3) {
13664
+ points.unshift(points[0]);
13665
+ }
13666
+ controlPoint1 = (this.calculateCurveControlPoints(points[0], points[1], points[2])).controlPoint2;
13667
+ controlPoint2 = (this.calculateCurveControlPoints(points[1], points[2], points[3])).controlPoint1;
13668
+ this.startPoint = points[1];
13669
+ this.controlPoint1 = controlPoint1;
13670
+ this.controlPoint2 = controlPoint2;
13671
+ this.endPoint = points[2];
13672
+ this.startDraw();
13673
+ points.shift();
13674
+ }
13675
+ }
13676
+ }
13677
+ startDraw() {
13678
+ let velocity;
13679
+ velocity = this.pointVelocityCalc(this.startPoint);
13680
+ velocity = this.velocity * velocity + (1 - this.velocity) * this.lastVelocity;
13681
+ const newWidth = Math.max(this.maxStrokeWidth / (velocity + 1), this.minStrokeWidth);
13682
+ this.curveDraw(this.lastWidth, newWidth);
13683
+ this.lastVelocity = velocity;
13684
+ this.lastWidth = newWidth;
13685
+ }
13686
+ endDraw() {
13687
+ const canDrawCurve = this.pointColl.length > 2;
13688
+ const point = this.pointColl[0];
13689
+ if (!canDrawCurve && point) {
13690
+ this.strokeDraw(point);
13691
+ }
13692
+ }
13693
+ /* Calculate the Bezier (x, y) coordinate of the curve. */
13694
+ curveDraw(startWidth, endWidth) {
13695
+ const context = this.canvasContext;
13696
+ let width;
13697
+ let i;
13698
+ let t1;
13699
+ let t2;
13700
+ let t3;
13701
+ let u1;
13702
+ let u2;
13703
+ let u3;
13704
+ let x;
13705
+ let y;
13706
+ const widthValue = endWidth - startWidth;
13707
+ const bezierLength = this.bezierLengthCalc();
13708
+ const drawSteps = Math.ceil(bezierLength) * 2;
13709
+ context.beginPath();
13710
+ for (i = 0; i < drawSteps; i++) {
13711
+ t1 = i / drawSteps;
13712
+ t2 = t1 * t1;
13713
+ t3 = t2 * t1;
13714
+ u1 = 1 - t1;
13715
+ u2 = u1 * u1;
13716
+ u3 = u2 * u1;
13717
+ x = u3 * this.startPoint.x;
13718
+ x += 3 * u2 * t1 * this.controlPoint1.x;
13719
+ x += 3 * u1 * t2 * this.controlPoint2.x;
13720
+ x += t3 * this.endPoint.x;
13721
+ y = u3 * this.startPoint.y;
13722
+ y += 3 * u2 * t1 * this.controlPoint1.y;
13723
+ y += 3 * u1 * t2 * this.controlPoint2.y;
13724
+ y += t3 * this.endPoint.y;
13725
+ width = Math.min(startWidth + t3 * widthValue, this.maxStrokeWidth);
13726
+ this.arcDraw(x, y, width);
13727
+ }
13728
+ context.closePath();
13729
+ context.fill();
13730
+ this.isSignatureEmpty = false;
13731
+ }
13732
+ strokeDraw(point) {
13733
+ const context = this.canvasContext;
13734
+ const pointSize = (this.minStrokeWidth + this.maxStrokeWidth) / 2;
13735
+ context.beginPath();
13736
+ this.arcDraw(point.x, point.y, pointSize);
13737
+ context.closePath();
13738
+ context.fill();
13739
+ this.isSignatureEmpty = false;
13740
+ }
13741
+ arcDraw(x, y, size) {
13742
+ const context = this.canvasContext;
13743
+ context.moveTo(x, y);
13744
+ context.arc(x, y, size, 0, 2 * Math.PI, false);
13745
+ }
13746
+ /* Utility functions for Bezier algorithm*/
13747
+ calculateCurveControlPoints(p1, p2, p3) {
13748
+ const dx1 = p1.x - p2.x;
13749
+ const dy1 = p1.y - p2.y;
13750
+ const dx2 = p2.x - p3.x;
13751
+ const dy2 = p2.y - p3.y;
13752
+ const m1 = { x: (p1.x + p2.x) / 2.0, y: (p1.y + p2.y) / 2.0 };
13753
+ const m2 = { x: (p2.x + p3.x) / 2.0, y: (p2.y + p3.y) / 2.0 };
13754
+ const l1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
13755
+ const l2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
13756
+ const dxm = (m1.x - m2.x);
13757
+ const dym = (m1.y - m2.y);
13758
+ const k = l2 / (l1 + l2);
13759
+ const cm = { x: m2.x + dxm * k, y: m2.y + dym * k };
13760
+ const tx = p2.x - cm.x;
13761
+ const ty = p2.y - cm.y;
13762
+ return {
13763
+ controlPoint1: this.point(m1.x + tx, m1.y + ty, 0),
13764
+ controlPoint2: this.point(m2.x + tx, m2.y + ty, 0)
13765
+ };
13766
+ }
13767
+ /* Returns approximated bezier length of the curuve.*/
13768
+ bezierLengthCalc() {
13769
+ const steps = 10;
13770
+ let length = 0;
13771
+ let i;
13772
+ let t;
13773
+ let pointx1;
13774
+ let pointy1;
13775
+ let pointx2;
13776
+ let pointy2;
13777
+ let pointx3;
13778
+ let pointy3;
13779
+ for (i = 0; i <= steps; i++) {
13780
+ t = i / steps;
13781
+ pointx1 = this.bezierPointCalc(t, this.startPoint.x, this.controlPoint1.x, this.controlPoint2.x, this.endPoint.x);
13782
+ pointy1 = this.bezierPointCalc(t, this.startPoint.y, this.controlPoint1.y, this.controlPoint2.y, this.endPoint.y);
13783
+ if (i > 0) {
13784
+ pointx3 = pointx1 - pointx2;
13785
+ pointy3 = pointy1 - pointy2;
13786
+ length += Math.sqrt(pointx3 * pointx3 + pointy3 * pointy3);
13787
+ }
13788
+ pointx2 = pointx1;
13789
+ pointy2 = pointy1;
13790
+ }
13791
+ return length;
13792
+ }
13793
+ /* Calculate parametric value of x or y given t and the
13794
+ four point(startpoint, controlpoint1, controlpoint2, endpoint) coordinates of a cubic bezier curve.*/
13795
+ bezierPointCalc(t, startpoint, cp1, cp2, endpoint) {
13796
+ return startpoint * (1.0 - t) * (1.0 - t) * (1.0 - t) + 3.0 * cp1 * (1.0 - t) * (1.0 - t) * t + 3.0 *
13797
+ cp2 * (1.0 - t) * t * t + endpoint * t * t * t;
13798
+ }
13799
+ /* Velocity between the current point and last point.*/
13800
+ pointVelocityCalc(startPoint) {
13801
+ return (this.time !== startPoint.time) ? this.distanceTo(startPoint) / (this.time - startPoint.time) : 0;
13802
+ }
13803
+ /* Distance between the current point and last point.*/
13804
+ distanceTo(start) {
13805
+ return Math.sqrt(Math.pow(this.pointX - start.x, 2) + Math.pow(this.pointY - start.y, 2));
13806
+ }
13807
+ isRead(isRead) {
13808
+ if (isRead) {
13809
+ EventHandler.remove(this.canvasContext.canvas, 'mousedown touchstart', this.mouseDownHandler);
13810
+ }
13811
+ else if (!this.disabled) {
13812
+ EventHandler.add(this.canvasContext.canvas, 'mousedown touchstart', this.mouseDownHandler, this);
13813
+ }
13814
+ }
13815
+ enableOrDisable(isDisable) {
13816
+ this.disabled = isDisable;
13817
+ if (isDisable) {
13818
+ this.reDraw('0.5');
13819
+ this.isRead(true);
13820
+ }
13821
+ else {
13822
+ this.reDraw('1');
13823
+ this.isRead(false);
13824
+ }
13825
+ }
13826
+ reDraw(opacity) {
13827
+ const data = this.canvasContext.getImageData(0, 0, this.element.width, this.element.height);
13828
+ this.canvasContext.clearRect(0, 0, this.element.width, this.element.height);
13829
+ this.element.style.opacity = opacity;
13830
+ this.canvasContext.putImageData(data, 0, 0);
13831
+ }
13832
+ updateSnapCollection(isClear) {
13833
+ if (isNullOrUndefined(this.incStep)) {
13834
+ this.incStep = -1;
13835
+ this.incStep++;
13836
+ this.snapColl = [];
13837
+ this.clearArray = [];
13838
+ }
13839
+ else {
13840
+ this.incStep++;
13841
+ }
13842
+ if (this.incStep < this.snapColl.length) {
13843
+ this.snapColl.length = this.incStep;
13844
+ }
13845
+ if (this.incStep > 0) {
13846
+ const canvasNew = this.createElement('canvas', { className: 'e-' + this.getModuleName() + '-wrapper' });
13847
+ const canvasContextNew = canvasNew.getContext('2d');
13848
+ canvasNew.width = this.canvasContext.canvas.width;
13849
+ canvasNew.height = this.canvasContext.canvas.height;
13850
+ canvasContextNew.drawImage(this.canvasContext.canvas, 0, 0, canvasNew.width, canvasNew.height);
13851
+ this.snapColl.push(canvasNew.toDataURL());
13852
+ }
13853
+ else {
13854
+ this.snapColl.push(this.canvasContext.canvas.toDataURL());
13855
+ }
13856
+ if (isClear) {
13857
+ this.clearArray.push(this.incStep);
13858
+ }
13859
+ }
13860
+ setBackgroundImage(imageSrc) {
13861
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
13862
+ const proxy = this;
13863
+ const imageObj = new Image();
13864
+ imageObj.crossOrigin = 'anonymous';
13865
+ imageObj.src = imageSrc;
13866
+ imageObj.onload = () => {
13867
+ proxy.canvasContext.globalCompositeOperation = 'source-over';
13868
+ proxy.canvasContext.drawImage(imageObj, 0, 0, proxy.element.width, proxy.element.height);
13869
+ proxy.updateSnapCollection();
13870
+ proxy.saveBackground(true);
13871
+ };
13872
+ this.canvasContext.clearRect(0, 0, this.canvasContext.canvas.width, this.canvasContext.canvas.height);
13873
+ }
13874
+ setBackgroundColor(color) {
13875
+ const canvasEle = this.canvasContext;
13876
+ canvasEle.strokeStyle = color;
13877
+ let i;
13878
+ let j;
13879
+ for (i = 1; i <= canvasEle.canvas.width; i++) {
13880
+ for (j = 1; j <= canvasEle.canvas.height; j++) {
13881
+ canvasEle.strokeRect(0, 0, i, j);
13882
+ }
13883
+ }
13884
+ this.updateSnapCollection();
13885
+ }
13886
+ loadPersistedSignature() {
13887
+ if (isNullOrUndefined(this.signatureValue)) {
13888
+ return;
13889
+ }
13890
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
13891
+ const proxy = this;
13892
+ const lastImage = new Image();
13893
+ lastImage.src = this.signatureValue;
13894
+ lastImage.onload = () => {
13895
+ proxy.canvasContext.clearRect(0, 0, proxy.element.width, proxy.element.height);
13896
+ proxy.canvasContext.drawImage(lastImage, 0, 0);
13897
+ proxy.updateSnapCollection();
13898
+ };
13899
+ this.isSignatureEmpty = false;
13900
+ }
13901
+ /**
13902
+ * To get the signature as Blob.
13903
+ *
13904
+ * @param {string} url - specify the url/base 64 string to get blob of the signature.
13905
+ * @returns {Blob}.
13906
+ */
13907
+ getBlob(url) {
13908
+ const arr = url.split(',');
13909
+ const type = arr[0].match(/:(.*?);/)[1];
13910
+ const bstr = atob(arr[1]);
13911
+ let n = bstr.length;
13912
+ const u8arr = new Uint8Array(n);
13913
+ while (n--) {
13914
+ u8arr[n] = bstr.charCodeAt(n);
13915
+ }
13916
+ return new Blob([u8arr], { type: type });
13917
+ }
13918
+ download(blob, fileName) {
13919
+ const blobUrl = URL.createObjectURL(blob);
13920
+ const a = document.createElement('a');
13921
+ a.href = blobUrl;
13922
+ a.target = '_parent';
13923
+ a.download = fileName;
13924
+ (document.body || document.documentElement).appendChild(a);
13925
+ a.click();
13926
+ a.parentNode.removeChild(a);
13927
+ }
13928
+ /**
13929
+ * To refresh the signature.
13930
+ *
13931
+ * @private
13932
+ * @returns {void}.
13933
+ */
13934
+ refresh() {
13935
+ this.pointColl = [];
13936
+ this.lastVelocity = 0;
13937
+ this.lastWidth = (this.minStrokeWidth + this.maxStrokeWidth) / 2;
13938
+ }
13939
+ /**
13940
+ * Erases all the signature strokes signed by user.
13941
+ *
13942
+ * @returns {void}.
13943
+ */
13944
+ clear() {
13945
+ const args = { actionName: 'clear' };
13946
+ this.canvasContext.clearRect(0, 0, this.canvasContext.canvas.width, this.canvasContext.canvas.height);
13947
+ this.refresh();
13948
+ this.updateSnapCollection(true);
13949
+ this.isSignatureEmpty = true;
13950
+ if (!this.isBlazor) {
13951
+ this.trigger('change', args);
13952
+ }
13953
+ else {
13954
+ this.dotnetRef.invokeMethodAsync('TriggerEventAsync', 'Clear');
13955
+ }
13956
+ }
13957
+ /**
13958
+ * Undo the last user action.
13959
+ *
13960
+ * @returns {void}.
13961
+ */
13962
+ undo() {
13963
+ const args = { actionName: 'undo' };
13964
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
13965
+ const proxy = this;
13966
+ if (this.incStep > 0) {
13967
+ this.incStep--;
13968
+ const undoImg = new Image();
13969
+ undoImg.src = this.snapColl[this.incStep];
13970
+ undoImg.onload = () => {
13971
+ proxy.canvasContext.clearRect(0, 0, proxy.element.width, proxy.element.height);
13972
+ proxy.canvasContext.drawImage(undoImg, 0, 0, proxy.element.width, proxy.element.height);
13973
+ };
13974
+ }
13975
+ this.isClear();
13976
+ if (!this.isBlazor) {
13977
+ this.trigger('change', args);
13978
+ }
13979
+ else {
13980
+ this.dotnetRef.invokeMethodAsync('TriggerEventAsync', 'Undo');
13981
+ }
13982
+ }
13983
+ /**
13984
+ * Redo the last user action.
13985
+ *
13986
+ * @returns {void}.
13987
+ */
13988
+ redo() {
13989
+ const args = { actionName: 'redo' };
13990
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
13991
+ const proxy = this;
13992
+ if (this.incStep < this.snapColl.length - 1) {
13993
+ this.incStep++;
13994
+ const redoImg = new Image();
13995
+ redoImg.src = this.snapColl[this.incStep];
13996
+ redoImg.onload = () => {
13997
+ proxy.canvasContext.clearRect(0, 0, proxy.element.width, proxy.element.height);
13998
+ proxy.canvasContext.drawImage(redoImg, 0, 0, proxy.element.width, proxy.element.height);
13999
+ };
14000
+ }
14001
+ this.isClear();
14002
+ if (!this.isBlazor) {
14003
+ this.trigger('change', args);
14004
+ }
14005
+ else {
14006
+ this.dotnetRef.invokeMethodAsync('TriggerEventAsync', 'Redo');
14007
+ }
14008
+ }
14009
+ isClear() {
14010
+ if (this.clearArray) {
14011
+ let empty = false;
14012
+ for (let i = 0; i < this.clearArray.length; i++) {
14013
+ if (this.clearArray[i] === this.incStep) {
14014
+ this.isSignatureEmpty = true;
14015
+ empty = true;
14016
+ }
14017
+ }
14018
+ if (!empty) {
14019
+ this.isSignatureEmpty = false;
14020
+ }
14021
+ }
14022
+ }
14023
+ /**
14024
+ * To check whether the signature is empty or not.
14025
+ *
14026
+ * @returns {boolean}.
14027
+ */
14028
+ isEmpty() {
14029
+ return this.isSignatureEmpty;
14030
+ }
14031
+ /**
14032
+ * To check whether the undo collection is empty or not.
14033
+ *
14034
+ * @returns {boolean}.
14035
+ */
14036
+ canUndo() {
14037
+ return this.incStep > 0;
14038
+ }
14039
+ /**
14040
+ * To check whether the redo collection is empty or not.
14041
+ *
14042
+ * @returns {boolean}.
14043
+ */
14044
+ canRedo() {
14045
+ return this.incStep < this.snapColl.length - 1;
14046
+ }
14047
+ /**
14048
+ * To draw the signature based on the given text, with the font family and font size.
14049
+ *
14050
+ * @param {string} text - specify text to be drawn as signature.
14051
+ * @param {string} fontFamily - specify font family of a signature.
14052
+ * @param {number} fontSize - specify font size of a signature.
14053
+ *
14054
+ * @returns {void}.
14055
+ */
14056
+ draw(text, fontFamily, fontSize) {
14057
+ this.canvasContext.clearRect(0, 0, this.canvasContext.canvas.width, this.canvasContext.canvas.height);
14058
+ fontFamily = fontFamily || 'Arial';
14059
+ fontSize = fontSize || 30;
14060
+ this.canvasContext.font = fontSize + 'px ' + fontFamily;
14061
+ this.canvasContext.textAlign = 'center';
14062
+ this.canvasContext.textBaseline = 'middle';
14063
+ this.canvasContext.fillText(text, this.element.width / 2, this.element.height / 2);
14064
+ this.updateSnapCollection();
14065
+ this.isSignatureEmpty = false;
14066
+ }
14067
+ /**
14068
+ * To load the signature with the given base 64 string, height and width.
14069
+ *
14070
+ * @param {string} signature - specify the url/base 64 string to be drawn as signature.
14071
+ * @param {number} width - specify the width of the loaded signature image.
14072
+ * @param {number} height - specify the height of the loaded signature image.
14073
+ * @returns {void}.
14074
+ */
14075
+ load(signature, width, height) {
14076
+ height = height || this.element.height;
14077
+ width = width || this.element.width;
14078
+ this.canvasContext.clearRect(0, 0, this.canvasContext.canvas.width, this.canvasContext.canvas.height);
14079
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
14080
+ const proxy = this;
14081
+ const bitmapImage = new Image();
14082
+ bitmapImage.src = signature;
14083
+ bitmapImage.onload = () => {
14084
+ Promise.all([
14085
+ createImageBitmap(bitmapImage, 0, 0, width, height)
14086
+ ]).then((results) => {
14087
+ const tempCanvas = document.createElement('canvas');
14088
+ tempCanvas.width = width;
14089
+ tempCanvas.height = height;
14090
+ tempCanvas.getContext('2d').drawImage(results[0], 0, 0);
14091
+ proxy.canvasContext.drawImage(tempCanvas, 0, 0, width, height, 0, 0, proxy.element.width, proxy.element.height);
14092
+ proxy.updateSnapCollection();
14093
+ });
14094
+ };
14095
+ this.isSignatureEmpty = false;
14096
+ }
14097
+ saveBackground(savebg) {
14098
+ let imageSrc;
14099
+ if (savebg && this.backgroundImage) {
14100
+ imageSrc = this.snapColl[this.incStep - 1];
14101
+ }
14102
+ else {
14103
+ imageSrc = this.snapColl[this.incStep];
14104
+ }
14105
+ if (!savebg) {
14106
+ this.canvasContext.clearRect(0, 0, this.canvasContext.canvas.width, this.canvasContext.canvas.height);
14107
+ if (this.backgroundImage) {
14108
+ this.setBackgroundImage(this.backgroundImage);
14109
+ }
14110
+ else if (this.backgroundColor) {
14111
+ this.setBackgroundColor(this.backgroundColor);
14112
+ savebg = true;
14113
+ }
14114
+ }
14115
+ if (savebg) {
14116
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
14117
+ const proxy = this;
14118
+ const imageObj = new Image();
14119
+ imageObj.crossOrigin = 'anonymous';
14120
+ imageObj.src = imageSrc;
14121
+ imageObj.onload = () => {
14122
+ proxy.backgroundLoaded = true;
14123
+ proxy.canvasContext.globalCompositeOperation = 'source-over';
14124
+ proxy.canvasContext.drawImage(imageObj, 0, 0, proxy.element.width, proxy.element.height);
14125
+ proxy.save(proxy.fileType, proxy.fileName);
14126
+ };
14127
+ }
14128
+ }
14129
+ /**
14130
+ * To save the signature with the given file type and file name.
14131
+ *
14132
+ * @param {SignatureFileType} type - specify type of the file to be saved a signature.
14133
+ * @param {string} fileName - specify name of the file to be saved a signature.
14134
+ *
14135
+ * @returns {void}.
14136
+ */
14137
+ save(type, fileName) {
14138
+ if (this.saveWithBackground && this.backgroundLoaded == null && (this.backgroundImage || this.backgroundColor)) {
14139
+ this.backgroundLoaded = false;
14140
+ this.fileType = type;
14141
+ this.fileName = fileName;
14142
+ this.saveBackground(false);
14143
+ }
14144
+ else if (type === 'Svg') {
14145
+ fileName = fileName || 'Signature';
14146
+ this.toSVG(fileName);
14147
+ }
14148
+ else if (type === 'Jpeg') {
14149
+ fileName = fileName || 'Signature';
14150
+ if (!this.saveWithBackground || this.saveWithBackground && !(this.backgroundImage || this.backgroundColor)) {
14151
+ this.toJPEG(fileName);
14152
+ }
14153
+ else {
14154
+ const dataURL = this.canvasContext.canvas.toDataURL('image/jpeg');
14155
+ this.download(this.getBlob(dataURL), fileName + '.' + 'jpeg');
14156
+ }
14157
+ }
14158
+ else {
14159
+ fileName = fileName || 'Signature';
14160
+ const dataURL = this.canvasContext.canvas.toDataURL('image/png');
14161
+ this.download(this.getBlob(dataURL), fileName + '.' + 'png');
14162
+ }
14163
+ if (this.saveWithBackground && this.backgroundLoaded) {
14164
+ this.resetSnap();
14165
+ }
14166
+ }
14167
+ resetSnap() {
14168
+ this.canvasContext.clearRect(0, 0, this.canvasContext.canvas.width, this.canvasContext.canvas.height);
14169
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
14170
+ const proxy = this;
14171
+ const restoreObj = new Image();
14172
+ restoreObj.src = this.snapColl[this.incStep - 1];
14173
+ restoreObj.onload = () => {
14174
+ proxy.canvasContext.drawImage(restoreObj, 0, 0, proxy.element.width, proxy.element.height);
14175
+ proxy.updateSnapCollection();
14176
+ };
14177
+ this.backgroundLoaded = null;
14178
+ this.snapColl.pop();
14179
+ this.incStep--;
14180
+ this.snapColl.pop();
14181
+ this.incStep--;
14182
+ }
14183
+ toJPEG(fileName) {
14184
+ const imageSrc = this.snapColl[this.incStep];
14185
+ this.setBackgroundColor('#ffffff');
14186
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
14187
+ const proxy = this;
14188
+ const imageObj = new Image();
14189
+ imageObj.crossOrigin = 'anonymous';
14190
+ imageObj.src = imageSrc;
14191
+ imageObj.onload = () => {
14192
+ proxy.canvasContext.globalCompositeOperation = 'source-over';
14193
+ proxy.canvasContext.drawImage(imageObj, 0, 0, proxy.element.width, proxy.element.height);
14194
+ const dataURL = proxy.canvasContext.canvas.toDataURL('image/jpeg');
14195
+ proxy.download(proxy.getBlob(dataURL), fileName + '.' + 'jpeg');
14196
+ proxy.canvasContext.clearRect(0, 0, proxy.canvasContext.canvas.width, proxy.canvasContext.canvas.height);
14197
+ this.resizeHandler();
14198
+ };
14199
+ this.snapColl.pop();
14200
+ this.incStep--;
14201
+ }
14202
+ toSVG(fileName) {
14203
+ const dataUrl = this.canvasContext.canvas.toDataURL();
14204
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
14205
+ svg.setAttribute('width', this.canvasContext.canvas.width.toString());
14206
+ svg.setAttribute('height', this.canvasContext.canvas.height.toString());
14207
+ const XLinkNS = 'http://www.w3.org/1999/xlink';
14208
+ const img = document.createElementNS('http://www.w3.org/2000/svg', 'image');
14209
+ img.setAttributeNS(null, 'height', this.canvasContext.canvas.height.toString());
14210
+ img.setAttributeNS(null, 'width', this.canvasContext.canvas.width.toString());
14211
+ img.setAttributeNS(XLinkNS, 'xlink:href', dataUrl);
14212
+ svg.appendChild(img);
14213
+ const prefix = 'data:image/svg+xml;base64,';
14214
+ const header = '<svg' + ' xmlns="http://www.w3.org/2000/svg"' + ' xmlns:xlink="http://www.w3.org/1999/xlink"'
14215
+ + ` width="${this.canvasContext.canvas.width}"` + ` height="${this.canvasContext.canvas.height}"` + '>';
14216
+ const footer = '</svg>';
14217
+ const body = svg.innerHTML;
14218
+ const data = header + body + footer;
14219
+ const svgDataUrl = prefix + btoa(data);
14220
+ if (fileName == null) {
14221
+ return svgDataUrl;
14222
+ }
14223
+ else {
14224
+ this.download(this.getBlob(svgDataUrl), fileName + '.' + 'svg');
14225
+ return null;
14226
+ }
14227
+ }
14228
+ /**
14229
+ * To save the signature as Blob.
14230
+ *
14231
+ * @returns {Blob}.
14232
+ */
14233
+ saveAsBlob() {
14234
+ return this.getBlob(this.canvasContext.canvas.toDataURL('image/png'));
14235
+ }
14236
+ /**
14237
+ * To get the signature as Base 64.
14238
+ *
14239
+ * @private
14240
+ * @param {SignatureFileType} type - Specifies the type of the image format.
14241
+ * @returns {string}.
14242
+ */
14243
+ getSignature(type) {
14244
+ if (type === 'Jpeg') {
14245
+ const imgData = this.canvasContext.getImageData(0, 0, this.element.width, this.element.height);
14246
+ const data = imgData.data;
14247
+ for (let i = 0; i < data.length; i += 4) {
14248
+ if (data[i + 3] < 255) {
14249
+ data[i] = 255 - data[i];
14250
+ data[i + 1] = 255 - data[i + 1];
14251
+ data[i + 2] = 255 - data[i + 2];
14252
+ data[i + 3] = 255 - data[i + 3];
14253
+ }
14254
+ }
14255
+ this.canvasContext.putImageData(imgData, 0, 0);
14256
+ const dataURL = this.canvasContext.canvas.toDataURL('image/jpeg');
14257
+ this.resizeHandler();
14258
+ return dataURL;
14259
+ }
14260
+ else if (type === 'Svg') {
14261
+ return this.toSVG(null);
14262
+ }
14263
+ else {
14264
+ return this.canvasContext.canvas.toDataURL('image/png');
14265
+ }
14266
+ }
14267
+ /**
14268
+ * Get component name.
14269
+ *
14270
+ * @returns {string} - Module Name
14271
+ * @private
14272
+ */
14273
+ getModuleName() {
14274
+ return 'signature';
14275
+ }
14276
+ /**
14277
+ * To get the properties to be maintained in the persisted state.
14278
+ *
14279
+ * @returns {string} - Persist data
14280
+ */
14281
+ getPersistData() {
14282
+ this.signatureValue = this.snapColl[this.incStep];
14283
+ return this.addOnPersist(['signatureValue']);
14284
+ }
14285
+ /**
14286
+ * Removes the component from the DOM and detaches all its related event handlers.
14287
+ * Also it maintains the initial input element from the DOM.
14288
+ *
14289
+ * @method destroy
14290
+ * @returns {void}
14291
+ */
14292
+ destroy() {
14293
+ this.unwireEvents(null);
14294
+ removeClass([this.element], 'e-' + this.getModuleName());
14295
+ this.element.removeAttribute('tabindex');
14296
+ this.pointColl = null;
14297
+ super.destroy();
14298
+ }
14299
+ /**
14300
+ * Modified onPropertyChanged method for both blazor and EJ2 signature component.
14301
+ *
14302
+ * @private
14303
+ * @param {string} key - Specifies the property, which changed.
14304
+ * @param {string} value - Specifies the property value changed.
14305
+ * @returns {void}
14306
+ */
14307
+ propertyChanged(key, value) {
14308
+ const canvasNew = this.canvasContext;
14309
+ switch (key) {
14310
+ case 'backgroundColor':
14311
+ canvasNew.canvas.style.backgroundColor = value;
14312
+ this.backgroundColor = value;
14313
+ break;
14314
+ case 'backgroundImage':
14315
+ canvasNew.canvas.style.backgroundImage = 'url(' + value + ')';
14316
+ this.backgroundImage = value;
14317
+ break;
14318
+ case 'strokeColor':
14319
+ canvasNew.fillStyle = value;
14320
+ this.strokeColor = value;
14321
+ break;
14322
+ case 'saveWithBackground':
14323
+ this.saveWithBackground = value;
14324
+ break;
14325
+ case 'maxStrokeWidth':
14326
+ this.maxStrokeWidth = value;
14327
+ break;
14328
+ case 'minStrokeWidth':
14329
+ this.minStrokeWidth = value;
14330
+ break;
14331
+ case 'velocity':
14332
+ this.velocity = value;
14333
+ break;
14334
+ case 'isReadOnly':
14335
+ this.isRead(value);
14336
+ break;
14337
+ case 'disabled':
14338
+ this.enableOrDisable(value);
14339
+ break;
14340
+ }
14341
+ }
14342
+ }
14343
+
14344
+ var __decorate$7 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
14345
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14346
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
14347
+ 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;
14348
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
14349
+ };
14350
+ /**
14351
+ * The Signature component allows user to draw smooth signatures as vector outline of strokes using variable width bezier curve interpolation.
14352
+ * It allows to save signature as image.
14353
+ * You can use your finger, pen, or mouse on a tablet, touchscreen, etc., to draw your own signature on this Signature component.
14354
+ * Signature component is a user interface to draw the Signature or Text.
14355
+ * It provides supports for various Background color, Stroke color and Background Image.
14356
+ * ```html
14357
+ * <canvas id="signature"></canvas>
14358
+ * ```
14359
+ * ```typescript
14360
+ * <script>
14361
+ * let signatureObj: Signature = new Signature(null , "#signature");
14362
+ * </script>
14363
+ * ```
14364
+ */
14365
+ let Signature = class Signature extends SignatureBase {
14366
+ /**
14367
+ * Constructor for creating the widget.
14368
+ *
14369
+ * @param {SignatureModel} options - Specifies the Signature model.
14370
+ * @param {string | HTMLCanvasElement} element - Specifies the element.
14371
+ * @private
14372
+ */
14373
+ constructor(options, element) {
14374
+ super(options, element);
14375
+ }
14376
+ preRender() {
14377
+ // pre render code snippets
14378
+ }
14379
+ /**
14380
+ * To Initialize the component rendering
14381
+ *
14382
+ * @private
14383
+ * @returns {void}
14384
+ */
14385
+ render() {
14386
+ this.initialize();
14387
+ }
14388
+ initialize() {
14389
+ addClass([this.element], 'e-' + this.getModuleName());
14390
+ super.initialize(this.element);
14391
+ if (this.enablePersistence) {
14392
+ this.loadPersistedSignature();
14393
+ }
14394
+ }
14395
+ /**
14396
+ * To get component name.
14397
+ *
14398
+ * @returns {string} - Module Name
14399
+ * @private
14400
+ */
14401
+ getModuleName() {
14402
+ return 'signature';
14403
+ }
14404
+ /**
14405
+ * To get the properties to be maintained in the persisted state.
14406
+ *
14407
+ * @returns {string} - Persist data
14408
+ */
14409
+ getPersistData() {
14410
+ return this.addOnPersist(['signatureValue']);
14411
+ }
14412
+ /**
14413
+ * Called internally if any of the property value changed.
14414
+ *
14415
+ * @param {SignatureModel} newProp - Specifies new properties
14416
+ * @param {SignatureModel} oldProp - Specifies old properties
14417
+ * @returns {void}
14418
+ * @private
14419
+ */
14420
+ onPropertyChanged(newProp, oldProp) {
14421
+ for (const prop of Object.keys(newProp)) {
14422
+ switch (prop) {
14423
+ case 'backgroundColor':
14424
+ super.propertyChanged(prop, newProp.backgroundColor);
14425
+ break;
14426
+ case 'backgroundImage':
14427
+ super.propertyChanged(prop, newProp.backgroundImage);
14428
+ break;
14429
+ case 'strokeColor':
14430
+ if (newProp.strokeColor !== oldProp.strokeColor) {
14431
+ super.propertyChanged(prop, newProp.strokeColor);
14432
+ }
14433
+ break;
14434
+ case 'saveWithBackground':
14435
+ super.propertyChanged(prop, newProp.saveWithBackground);
14436
+ break;
14437
+ case 'isReadOnly':
14438
+ super.propertyChanged(prop, newProp.isReadOnly);
14439
+ break;
14440
+ case 'disabled':
14441
+ super.propertyChanged(prop, newProp.disabled);
14442
+ break;
14443
+ }
14444
+ }
14445
+ }
14446
+ };
14447
+ __decorate$7([
14448
+ Property('')
14449
+ ], Signature.prototype, "backgroundColor", void 0);
14450
+ __decorate$7([
14451
+ Property('')
14452
+ ], Signature.prototype, "backgroundImage", void 0);
14453
+ __decorate$7([
14454
+ Property(false)
14455
+ ], Signature.prototype, "disabled", void 0);
14456
+ __decorate$7([
14457
+ Property(false)
14458
+ ], Signature.prototype, "isReadOnly", void 0);
14459
+ __decorate$7([
14460
+ Property(true)
14461
+ ], Signature.prototype, "saveWithBackground", void 0);
14462
+ __decorate$7([
14463
+ Property('#000000')
14464
+ ], Signature.prototype, "strokeColor", void 0);
14465
+ __decorate$7([
14466
+ Property(0.5)
14467
+ ], Signature.prototype, "minStrokeWidth", void 0);
14468
+ __decorate$7([
14469
+ Property(2)
14470
+ ], Signature.prototype, "maxStrokeWidth", void 0);
14471
+ __decorate$7([
14472
+ Property(0.7)
14473
+ ], Signature.prototype, "velocity", void 0);
14474
+ __decorate$7([
14475
+ Property('en-US')
14476
+ ], Signature.prototype, "locale", void 0);
14477
+ __decorate$7([
14478
+ Property(false)
14479
+ ], Signature.prototype, "enableRtl", void 0);
14480
+ __decorate$7([
14481
+ Property(false)
14482
+ ], Signature.prototype, "enablePersistence", void 0);
14483
+ __decorate$7([
14484
+ Event()
14485
+ ], Signature.prototype, "beforeSave", void 0);
14486
+ __decorate$7([
14487
+ Event()
14488
+ ], Signature.prototype, "change", void 0);
14489
+ __decorate$7([
14490
+ Event()
14491
+ ], Signature.prototype, "created", void 0);
14492
+ Signature = __decorate$7([
14493
+ NotifyPropertyChanges
14494
+ ], Signature);
14495
+
14496
+ /**
14497
+ * Signature modules
14498
+ */
14499
+
14500
+ /**
14501
+ * Signature base modules
14502
+ */
14503
+
13392
14504
  /**
13393
14505
  * NumericTextBox all modules
13394
14506
  */
13395
14507
 
13396
- 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 };
14508
+ 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 };
13397
14509
  //# sourceMappingURL=ej2-inputs.es2015.js.map