@syncfusion/ej2-inputs 19.3.48 → 19.4.41

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