{"version":3,"file":"ajf-material-signature.mjs","sources":["../../../projects/material/signature/src/signature.ts","../../../projects/material/signature/src/signature.html","../../../projects/material/signature/src/signature-module.ts","../../../projects/material/signature/src/public_api.ts","../../../projects/material/signature/src/ajf-material-signature.ts"],"sourcesContent":["/**\n * @license\n * Copyright (C) Gnucoop soc. coop.\n *\n * This file is part of the Advanced JSON forms (ajf).\n *\n * Advanced JSON forms (ajf) is free software: you can redistribute it and/or\n * modify it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the License,\n * or (at your option) any later version.\n *\n * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero\n * General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with Advanced JSON forms (ajf).\n * If not, see http://www.gnu.org/licenses/.\n *\n */\n\nimport {AjfSignature} from '@ajf/core/signature';\nimport {\n  AfterViewInit,\n  ChangeDetectionStrategy,\n  ChangeDetectorRef,\n  Component,\n  forwardRef,\n  OnDestroy,\n  Renderer2,\n  ViewEncapsulation,\n} from '@angular/core';\nimport {NG_VALUE_ACCESSOR} from '@angular/forms';\n\nexport const SIGNATURE_CONTROL_VALUE_ACCESSOR: any = {\n  provide: NG_VALUE_ACCESSOR,\n  useExisting: forwardRef(() => AjfSignatureComponent),\n  multi: true,\n};\n\n/**\n * Ajf signature component.\n */\n@Component({\n  selector: 'ajf-signature',\n  templateUrl: 'signature.html',\n  styleUrls: ['signature.scss'],\n  encapsulation: ViewEncapsulation.None,\n  changeDetection: ChangeDetectionStrategy.OnPush,\n  providers: [SIGNATURE_CONTROL_VALUE_ACCESSOR],\n})\nexport class AjfSignatureComponent extends AjfSignature implements OnDestroy, AfterViewInit {\n  constructor(cdr: ChangeDetectorRef, renderer: Renderer2) {\n    super(cdr, renderer);\n  }\n\n  ngAfterViewInit(): void {\n    this.sigPadElement = this.sigPad.nativeElement;\n    this.context = this.sigPadElement?.getContext('2d') ?? null;\n  }\n\n  clear() {\n    if (this.context != null && this.sigPadElement != null) {\n      this.context.clearRect(0, 0, this.sigPadElement.width, this.sigPadElement.height);\n      this.context.beginPath();\n    }\n    this.isDrawn = false;\n    this.value = null;\n  }\n\n  accept() {\n    if (this.sigPadElement != null) {\n      const signaturDataUrl = this.sigPadElement.toDataURL('image/png');\n      const head = 'data:image/png;base64,';\n      const imgFileSize = Math.round(((signaturDataUrl.length - head.length) * 3) / 4).toString();\n      this.value = {\n        name: 'signature.png',\n        type: 'image/png',\n        signature: true,\n        size: imgFileSize,\n        content: signaturDataUrl,\n      };\n    }\n  }\n\n  ngOnDestroy(): void {\n    return;\n  }\n}\n","<div class=\"ajf-signature-container\">\n  <p class=\"ajf-signature-text\">{{'Please sign here'|transloco}}</p>\n  <canvas\n    class=\"ajf-signature-canvas\"\n    #sigPad\n    (mousedown)=\"onMouseDown($event)\"\n    (mousemove)=\"onMouseMove($event)\"\n    (touchstart)=\"onMouseDown($event)\"\n    (touchmove)=\"onMouseMove($event)\"\n  ></canvas>\n  <div class=\"ajf-signature-actions\">\n    <button mat-fab (click)=\"clear()\" class=\"ajf-signature-action-clear\">\n      <mat-icon>close</mat-icon>\n    </button>\n    <button mat-fab (click)=\"accept()\" color=\"primary\" [disabled]=\"!isDrawn\" class=\"ajf-signature-action-accept\">\n      <mat-icon>check</mat-icon>\n    </button>\n  </div>\n\n  <img class=\"ajf-signature-preview\" [src]=\"value?.content\" />\n</div>\n","/**\n * @license\n * Copyright (C) Gnucoop soc. coop.\n *\n * This file is part of the Advanced JSON forms (ajf).\n *\n * Advanced JSON forms (ajf) is free software: you can redistribute it and/or\n * modify it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the License,\n * or (at your option) any later version.\n *\n * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero\n * General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with Advanced JSON forms (ajf).\n * If not, see http://www.gnu.org/licenses/.\n *\n */\n\nimport {AjfCommonModule} from '@ajf/core/common';\nimport {AjfTranslocoModule} from '@ajf/core/transloco';\nimport {CommonModule} from '@angular/common';\nimport {NgModule} from '@angular/core';\nimport {MatButtonModule} from '@angular/material/button';\nimport {MatIconModule} from '@angular/material/icon';\n\nimport {AjfSignatureComponent} from './signature';\nimport {FormsModule} from '@angular/forms';\n\n@NgModule({\n  imports: [\n    AjfCommonModule,\n    AjfTranslocoModule,\n    CommonModule,\n    FormsModule,\n    MatButtonModule,\n    MatIconModule,\n  ],\n  declarations: [AjfSignatureComponent],\n  exports: [AjfSignatureComponent],\n})\nexport class AjfSignatureModule {}\n","/**\n * @license\n * Copyright (C) Gnucoop soc. coop.\n *\n * This file is part of the Advanced JSON forms (ajf).\n *\n * Advanced JSON forms (ajf) is free software: you can redistribute it and/or\n * modify it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the License,\n * or (at your option) any later version.\n *\n * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero\n * General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with Advanced JSON forms (ajf).\n * If not, see http://www.gnu.org/licenses/.\n *\n */\n\nexport * from './signature';\nexport * from './signature-module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;AAoBG;AAeU,MAAA,gCAAgC,GAAQ;AACnD,IAAA,OAAO,EAAE,iBAAiB;AAC1B,IAAA,WAAW,EAAE,UAAU,CAAC,MAAM,qBAAqB,CAAC;AACpD,IAAA,KAAK,EAAE,IAAI;;AAGb;;AAE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