libey-ng-component-library 0.0.19 → 0.0.21

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.
@@ -496,6 +496,23 @@ class SigWebTablet {
496
496
  }
497
497
  return '';
498
498
  }
499
+ static SigWebGetVersion(prop) {
500
+ try {
501
+ var xhr = this.SigWebcreateXHR();
502
+ if (xhr) {
503
+ xhr.open('GET', this.baseUri + prop + '?noCache=' + this.generateUUID(), false);
504
+ xhr.send(null);
505
+ if (xhr.readyState == 4 && xhr.status == 200) {
506
+ return xhr.responseText;
507
+ }
508
+ }
509
+ }
510
+ catch (error) {
511
+ console.error('Error en SigWebGetVersion:', error);
512
+ return null;
513
+ }
514
+ return null;
515
+ }
499
516
  static SigWebGetProperty(prop) {
500
517
  var xhr = this.SigWebcreateXHR();
501
518
  if (xhr) {
@@ -753,7 +770,9 @@ class SigWebTablet {
753
770
  static GetVersionString() {
754
771
  var Prop = 'Version';
755
772
  Prop = Prop;
756
- var Str = this.SigWebGetProperty(Prop);
773
+ var Str = this.SigWebGetVersion(Prop);
774
+ if (Str == null)
775
+ return Str;
757
776
  var trimStr = Str.slice(1, Str.length - 2);
758
777
  return trimStr;
759
778
  }
@@ -1783,8 +1802,10 @@ class LibeyNgSignatureComponent {
1783
1802
  minWidth: 5,
1784
1803
  canvasWidth: this.widthView,
1785
1804
  canvasHeight: this.heightView,
1786
- backgroundColor: 'rgba(242,242,242,1)',
1787
1805
  };
1806
+ this.FileValidated = false;
1807
+ this.NotDriver = false;
1808
+ this.UploadFile = null;
1788
1809
  }
1789
1810
  ngAfterViewInit() {
1790
1811
  this.InitDevice();
@@ -1794,6 +1815,9 @@ class LibeyNgSignatureComponent {
1794
1815
  this._destroy$.next(true);
1795
1816
  }
1796
1817
  ChangeDevice() {
1818
+ this.NotDriver = false;
1819
+ this.UploadFile = null;
1820
+ this.File = null;
1797
1821
  setTimeout(() => {
1798
1822
  this.InitDevice();
1799
1823
  }, 200);
@@ -1812,62 +1836,126 @@ class LibeyNgSignatureComponent {
1812
1836
  SigWebTablet.SetTabletState(0, this.tmr, null);
1813
1837
  }
1814
1838
  onSign() {
1815
- console.log('onSign Clicked!');
1816
- SigWebTablet.SetDisplayXSize(this.widthRender);
1817
- SigWebTablet.SetDisplayYSize(this.heightRender);
1818
- SigWebTablet.SetTabletState(0, this.tmr, null);
1819
- SigWebTablet.SetJustifyMode(0);
1820
- SigWebTablet.ClearTablet();
1821
- if (this.tmr == null) {
1822
- this.tmr = SigWebTablet.SetTabletState(1, this.cnvContext, 50);
1839
+ this.NotDriver = false;
1840
+ this.UploadFile = null;
1841
+ var driver = SigWebTablet.GetVersionString();
1842
+ if (driver == null) {
1843
+ this.NotDriver = true;
1823
1844
  }
1824
1845
  else {
1846
+ this.NotDriver = false;
1847
+ console.log('onSign Clicked!');
1848
+ SigWebTablet.SetDisplayXSize(this.widthRender);
1849
+ SigWebTablet.SetDisplayYSize(this.heightRender);
1825
1850
  SigWebTablet.SetTabletState(0, this.tmr, null);
1826
- this.tmr = null;
1827
- this.tmr = SigWebTablet.SetTabletState(1, this.cnvContext, 50);
1851
+ SigWebTablet.SetJustifyMode(0);
1852
+ SigWebTablet.ClearTablet();
1853
+ if (this.tmr == null) {
1854
+ this.tmr = SigWebTablet.SetTabletState(1, this.cnvContext, 50);
1855
+ }
1856
+ else {
1857
+ SigWebTablet.SetTabletState(0, this.tmr, null);
1858
+ this.tmr = null;
1859
+ this.tmr = SigWebTablet.SetTabletState(1, this.cnvContext, 50);
1860
+ }
1828
1861
  }
1829
1862
  }
1830
1863
  onClear() {
1831
- if (this.DeviceType == 'pinpad') {
1832
- SigWebTablet.ClearTablet();
1833
- if (this.cnvContext) {
1834
- this.cnvContext.clearRect(0, 0, this.canvas.nativeElement.width, this.canvas.nativeElement.height);
1864
+ if (this.UploadFile == null) {
1865
+ if (this.DeviceType == 'pinpad') {
1866
+ SigWebTablet.ClearTablet();
1867
+ if (this.cnvContext) {
1868
+ this.cnvContext.clearRect(0, 0, this.canvas.nativeElement.width, this.canvas.nativeElement.height);
1869
+ }
1870
+ }
1871
+ if (this.DeviceType == 'mousepad') {
1872
+ this.signaturePad.clear();
1835
1873
  }
1836
1874
  }
1837
- if (this.DeviceType == 'mousepad') {
1838
- this.signaturePad.clear();
1875
+ else {
1876
+ this.File = null;
1877
+ this.UploadFile = null;
1878
+ this.ChangeDevice();
1839
1879
  }
1840
1880
  }
1841
1881
  onDone() {
1842
- if (this.DeviceType == 'pinpad') {
1843
- // if (Number(SigWebTablet.NumberOfTabletPoints()) === 0) {
1844
- // alert('Por favor firme antes de continuar');
1845
- // } else {
1846
- SigWebTablet.SetTabletState(0, this.tmr, null);
1847
- SigWebTablet.SetSigCompressionMode(1);
1848
- var result = new OutputMessage();
1849
- result.bioSigData = SigWebTablet.GetSigString();
1850
- result.sigImgData = SigWebTablet.GetSigString();
1851
- SigWebTablet.SetImageXSize(this.widthRender);
1852
- SigWebTablet.SetImageYSize(this.heightRender);
1853
- SigWebTablet.SetImagePenWidth(5);
1854
- SigWebTablet.GetSigImageB64((base64) => {
1855
- result.sigString = "data:image/png;base64," + base64;
1882
+ var result = new OutputMessage();
1883
+ if (this.UploadFile == null) {
1884
+ if (this.DeviceType == 'pinpad') {
1885
+ // if (Number(SigWebTablet.NumberOfTabletPoints()) === 0) {
1886
+ // alert('Por favor firme antes de continuar');
1887
+ // } else {
1888
+ SigWebTablet.SetTabletState(0, this.tmr, null);
1889
+ SigWebTablet.SetSigCompressionMode(1);
1890
+ result.bioSigData = SigWebTablet.GetSigString();
1891
+ result.sigImgData = SigWebTablet.GetSigString();
1892
+ SigWebTablet.SetImageXSize(this.widthRender);
1893
+ SigWebTablet.SetImageYSize(this.heightRender);
1894
+ SigWebTablet.SetImagePenWidth(5);
1895
+ SigWebTablet.GetSigImageB64((base64) => {
1896
+ result.sigString = "data:image/png;base64," + base64;
1897
+ this.OutputSignature.emit(result);
1898
+ });
1899
+ // }
1900
+ }
1901
+ if (this.DeviceType == 'mousepad') {
1902
+ var result = new OutputMessage();
1903
+ result.sigString = this.signaturePad.toDataURL();
1856
1904
  this.OutputSignature.emit(result);
1857
- });
1858
- // }
1905
+ }
1859
1906
  }
1860
- if (this.DeviceType == 'mousepad') {
1861
- var result = new OutputMessage();
1862
- result.sigString = this.signaturePad.toDataURL();
1907
+ else {
1908
+ result.sigString = this.UploadFile;
1863
1909
  this.OutputSignature.emit(result);
1864
1910
  }
1865
1911
  }
1866
- drawComplete() { }
1867
- drawStart() { }
1912
+ fileEvent(event) {
1913
+ this.UploadFile = null;
1914
+ this.FileValidated = false;
1915
+ const file = event.target.files[0];
1916
+ if (file.type == 'image/jpeg' || file.type == 'image/png') {
1917
+ this.FileValidated = false;
1918
+ const newWidth = this.widthRender;
1919
+ const newHeight = this.heightRender;
1920
+ this.resizeImage(file, newWidth, newHeight)
1921
+ .then((resizedImageDataUrl) => {
1922
+ this.UploadFile = resizedImageDataUrl;
1923
+ })
1924
+ .catch((error) => {
1925
+ console.error('Error al redimensionar la imagen:', error);
1926
+ });
1927
+ }
1928
+ else {
1929
+ this.File = null;
1930
+ this.UploadFile = null;
1931
+ this.FileValidated = true;
1932
+ }
1933
+ }
1934
+ resizeImage(image, newWidth, newHeight) {
1935
+ return new Promise((resolve, reject) => {
1936
+ const reader = new FileReader();
1937
+ reader.onload = (e) => {
1938
+ const img = new Image();
1939
+ img.src = e.target.result;
1940
+ img.onload = () => {
1941
+ const canvas = document.createElement('canvas');
1942
+ const ctx = canvas.getContext('2d');
1943
+ canvas.width = newWidth;
1944
+ canvas.height = newHeight;
1945
+ ctx.drawImage(img, 0, 0, newWidth, newHeight);
1946
+ const resizedImageDataUrl = canvas.toDataURL(image.type);
1947
+ resolve(resizedImageDataUrl);
1948
+ };
1949
+ img.onerror = (error) => {
1950
+ reject(error);
1951
+ };
1952
+ };
1953
+ reader.readAsDataURL(image);
1954
+ });
1955
+ }
1868
1956
  }
1869
1957
  LibeyNgSignatureComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LibeyNgSignatureComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1870
- LibeyNgSignatureComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.17", type: LibeyNgSignatureComponent, selector: "lib-libey-ng-signature", inputs: { DeviceType: "DeviceType" }, outputs: { OutputSignature: "OutputSignature" }, viewQueries: [{ propertyName: "canvas", first: true, predicate: ["sigImg"], descendants: true }, { propertyName: "signaturePad", first: true, predicate: SignaturePad, descendants: true }], ngImport: i0, template: "<div class=\"container\">\n <div *ngIf=\"DeviceType=='pinpad'\">\n <canvas #sigImg [width]=\"widthView\" [height]=\"heightView\" style=\"background-color: rgba(242,242,242,1);\"></canvas> \n </div>\n <div *ngIf=\"DeviceType=='mousepad'\">\n <signature-pad [options]=\"signaturePadOptions\" (onBeginEvent)=\"drawStart()\" (onEndEvent)=\"drawComplete()\"></signature-pad>\n </div>\n <div class=\"row\">\n <button *ngIf=\"DeviceType=='pinpad'\" mat-raised-button (click)=\"onSign()\">Firmar</button>\n <button mat-raised-button (click)=\"onClear()\">Limpiar</button>\n <button mat-raised-button (click)=\"onDone()\">Guardar</button>\n </div>\n <div class=\"row\">\n <ng-select [(ngModel)]=\"DeviceType\" class=\"ng-select\" placeholder=\"Seleccionar\" [clearable]=\"false\"\n (change)=\"ChangeDevice()\">\n <ng-option [value]=\"'pinpad'\">Pinpad</ng-option>\n <ng-option [value]=\"'mousepad'\">Mousepad</ng-option>\n </ng-select>\n </div>\n</div>", styles: [".container{display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center}.row{display:flex;justify-content:center;grid-gap:10px;gap:10px}\n"], components: [{ type: i1$1.SignaturePad, selector: "signature-pad", inputs: ["options"], outputs: ["onBeginEvent", "onEndEvent"] }, { type: i2.NgSelectComponent, selector: "ng-select", inputs: ["markFirst", "dropdownPosition", "loading", "closeOnSelect", "hideSelected", "selectOnTab", "bufferAmount", "selectableGroup", "selectableGroupAsModel", "searchFn", "trackByFn", "clearOnBackspace", "labelForId", "inputAttrs", "readonly", "searchWhileComposing", "minTermLength", "editableSearchTerm", "keyDownFn", "multiple", "addTag", "searchable", "clearable", "isOpen", "items", "compareWith", "clearSearchOnAdd", "bindLabel", "placeholder", "notFoundText", "typeToSearchText", "addTagText", "loadingText", "clearAllText", "virtualScroll", "openOnEnter", "appendTo", "bindValue", "appearance", "maxSelectedItems", "groupBy", "groupValue", "tabIndex", "typeahead"], outputs: ["blur", "focus", "change", "open", "close", "search", "clear", "add", "remove", "scroll", "scrollToEnd"] }, { type: i2.ɵr, selector: "ng-option", inputs: ["disabled", "value"] }], directives: [{ type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i4.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }] });
1958
+ LibeyNgSignatureComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.17", type: LibeyNgSignatureComponent, selector: "lib-libey-ng-signature", inputs: { DeviceType: "DeviceType" }, outputs: { OutputSignature: "OutputSignature" }, viewQueries: [{ propertyName: "canvas", first: true, predicate: ["sigImg"], descendants: true }, { propertyName: "signaturePad", first: true, predicate: SignaturePad, descendants: true }], ngImport: i0, template: "<div class=\"container\">\n <div *ngIf=\"UploadFile==null\">\n <div *ngIf=\"DeviceType=='pinpad'\" style=\"cursor: pointer; border: 1px ridge #d2d2d2;\">\n <canvas (click)=\"onSign()\" #sigImg [width]=\"widthView\" [height]=\"heightView\"></canvas> \n </div>\n <div *ngIf=\"DeviceType=='mousepad'\" style=\"border: 1px ridge #d2d2d2;\">\n <signature-pad [options]=\"signaturePadOptions\"></signature-pad>\n </div>\n </div>\n <div *ngIf=\"UploadFile!=null\" style=\"border: 1px ridge #d2d2d2;\">\n <img [src]=\"UploadFile\" [width]=\"widthView\" [height]=\"heightView\" />\n </div>\n</div>\n<div class=\"row\">\n <div class=\"col-md-12\" style=\"padding-top: 17px !important; padding-bottom: 17px !important;\">\n <input type=\"file\" (change)=\"fileEvent($event)\" [(ngModel)]=\"File\" class=\"form-control form-control-ph\"\n accept=\"image/png, image/jpeg\" style=\"border: none;\">\n <label *ngIf=\"FileValidated\" [ngClass]=\"'text-danger'\">Archivo requerido. Formatos permitidos (jpeg, jpg, png)</label>\n </div>\n</div>\n<div class=\"row\">\n <div class=\"col-md-6\">\n <ng-select [(ngModel)]=\"DeviceType\" class=\"ng-select\" placeholder=\"Seleccionar\" [clearable]=\"false\"\n (change)=\"ChangeDevice()\">\n <ng-option [value]=\"'pinpad'\">Pinpad</ng-option>\n <ng-option [value]=\"'mousepad'\">Mousepad</ng-option>\n </ng-select>\n <label *ngIf=\"NotDriver\" [ngClass]=\"'text-danger'\">No tiene el driver instalado</label>\n </div>\n <div class=\"col-md-6\">\n <p class=\"text-primary font-link-rp\" style=\"text-align: right; cursor: pointer;\" (click)=\"onClear()\">\n Limpiar firma\n </p>\n </div>\n</div>\n\n<div class=\"modal-footer mt-15 mb-4\">\n <button type=\"button\" class=\"btn btn-primary btn-save-rp\" (click)=\"onDone()\"> \n <i class=\"icon-save-white\"></i> Guardar\n </button>\n</div>", styles: [".container{display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center}\n"], components: [{ type: i1$1.SignaturePad, selector: "signature-pad", inputs: ["options"], outputs: ["onBeginEvent", "onEndEvent"] }, { type: i2.NgSelectComponent, selector: "ng-select", inputs: ["markFirst", "dropdownPosition", "loading", "closeOnSelect", "hideSelected", "selectOnTab", "bufferAmount", "selectableGroup", "selectableGroupAsModel", "searchFn", "trackByFn", "clearOnBackspace", "labelForId", "inputAttrs", "readonly", "searchWhileComposing", "minTermLength", "editableSearchTerm", "keyDownFn", "multiple", "addTag", "searchable", "clearable", "isOpen", "items", "compareWith", "clearSearchOnAdd", "bindLabel", "placeholder", "notFoundText", "typeToSearchText", "addTagText", "loadingText", "clearAllText", "virtualScroll", "openOnEnter", "appendTo", "bindValue", "appearance", "maxSelectedItems", "groupBy", "groupValue", "tabIndex", "typeahead"], outputs: ["blur", "focus", "change", "open", "close", "search", "clear", "add", "remove", "scroll", "scrollToEnd"] }, { type: i2.ɵr, selector: "ng-option", inputs: ["disabled", "value"] }], directives: [{ type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i4.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { type: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i4.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }] });
1871
1959
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LibeyNgSignatureComponent, decorators: [{
1872
1960
  type: Component,
1873
1961
  args: [{