@colijnit/sharedcomponents 262.1.11 → 262.1.12

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.
@@ -293,7 +293,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
293
293
  PDFJS.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url).toString();
294
294
  class DocsignComponent {
295
295
  _changeDetector;
296
- iframe;
296
+ pdfContainer;
297
297
  /**
298
298
  * Load an existing [[PDFDocument]]. The input data can be provided in
299
299
  * multiple formats:
@@ -408,31 +408,40 @@ class DocsignComponent {
408
408
  this.showSigSeller = false;
409
409
  this._savePdf();
410
410
  }
411
- openPdfInNewTab() {
412
- if (!this._pdf) {
413
- return;
414
- }
415
- const blob = new Blob([this._pdf], {
416
- type: 'application/pdf'
417
- });
418
- const url = URL.createObjectURL(blob);
419
- window.open(url, '_blank');
420
- // Optional cleanup later
421
- setTimeout(() => URL.revokeObjectURL(url), 60_000);
422
- }
423
411
  async _openPDF() {
424
- this._checkSignatures();
425
- this.pdfDoc = await PDFDocument.load(this._pdf, {
412
+ await this._checkSignatures();
413
+ this.pdfDoc = await PDFDocument.load(this._getPdfBytesCopy(), {
426
414
  updateMetadata: false
427
415
  });
428
- if (this._isIOS()) {
429
- this.openPdfInNewTab();
430
- return;
431
- }
432
- const pdfDataUri = await this.pdfDoc.saveAsBase64({ dataUri: true });
433
- this.iframe.nativeElement.src = pdfDataUri;
416
+ await this._renderPdfPages();
434
417
  this._changeDetector.detectChanges();
435
418
  }
419
+ async _renderPdfPages() {
420
+ const container = this.pdfContainer.nativeElement;
421
+ container.innerHTML = '';
422
+ const pdfReader = await PDFJS.getDocument({
423
+ data: this._getPdfBytesCopy()
424
+ }).promise;
425
+ for (let pageNumber = 1; pageNumber <= pdfReader.numPages; pageNumber++) {
426
+ const page = await pdfReader.getPage(pageNumber);
427
+ const viewport = page.getViewport({ scale: 1.5 });
428
+ const canvas = document.createElement('canvas');
429
+ canvas.className = 'pdf-page';
430
+ canvas.width = viewport.width;
431
+ canvas.height = viewport.height;
432
+ const context = canvas.getContext('2d');
433
+ if (!context) {
434
+ continue;
435
+ }
436
+ await page.render({
437
+ canvas,
438
+ canvasContext: context,
439
+ viewport
440
+ }).promise;
441
+ container.appendChild(canvas);
442
+ page.cleanup();
443
+ }
444
+ }
436
445
  async _savePdf() {
437
446
  if (!this.showSigBuyer && !this.showSigSeller) {
438
447
  // ready, save the pdf and emit result
@@ -444,17 +453,9 @@ class DocsignComponent {
444
453
  if (!this._pdf) {
445
454
  return;
446
455
  }
447
- // let pdfWorkerSrc;
448
- // if (window.hasOwnProperty('pdfWorkerSrc') &&
449
- // typeof (window as any).pdfWorkerSrc === 'string' &&
450
- // (window as any).pdfWorkerSrc) {
451
- // pdfWorkerSrc = (window as any).pdfWorkerSrc;
452
- // }
453
- // else {
454
- // pdfWorkerSrc = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${PDFJS.version}/pdf.worker.min.mjs`;
455
- // }
456
- // PDFJS.GlobalWorkerOptions.workerSrc = pdfWorkerSrc;
457
- const pdfReader = await PDFJS.getDocument(this._pdf).promise;
456
+ const pdfReader = await PDFJS.getDocument({
457
+ data: this._getPdfBytesCopy()
458
+ }).promise;
458
459
  const numPages = pdfReader.numPages;
459
460
  for (let i = 0; i < numPages; i++) {
460
461
  const page = await pdfReader.getPage(i + 1);
@@ -511,13 +512,18 @@ class DocsignComponent {
511
512
  }
512
513
  this._pdf = bytes;
513
514
  }
514
- _isIOS() {
515
- return /iPad|iPhone|iPod/.test(navigator.userAgent)
516
- || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
515
+ _getPdfBytesCopy() {
516
+ if (this._pdf instanceof Uint8Array) {
517
+ return new Uint8Array(this._pdf);
518
+ }
519
+ if (this._pdf instanceof ArrayBuffer) {
520
+ return new Uint8Array(this._pdf.slice(0));
521
+ }
522
+ return new Uint8Array(this._pdf);
517
523
  }
518
524
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: DocsignComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
519
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.16", type: DocsignComponent, isStandalone: false, selector: "co-docsign", inputs: { pdf: "pdf", firstSignatureLabel: "firstSignatureLabel", firstSignatureField: "firstSignatureField", secondSignatureLabel: "secondSignatureLabel", secondSignatureField: "secondSignatureField", saveButtonLabel: "saveButtonLabel", clearButtonLabel: "clearButtonLabel", signDocumentButtonLabel: "signDocumentButtonLabel", cancelButtonLabel: "cancelButtonLabel" }, outputs: { pdfSaved: "pdfSaved", cancelClick: "cancelClick" }, host: { properties: { "class.co-docsign": "this.showClass" } }, viewQueries: [{ propertyName: "iframe", first: true, predicate: ["iframe"], descendants: true, read: ElementRef }], ngImport: i0, template: `
520
- <iframe #iframe></iframe>
525
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.16", type: DocsignComponent, isStandalone: false, selector: "co-docsign", inputs: { pdf: "pdf", firstSignatureLabel: "firstSignatureLabel", firstSignatureField: "firstSignatureField", secondSignatureLabel: "secondSignatureLabel", secondSignatureField: "secondSignatureField", saveButtonLabel: "saveButtonLabel", clearButtonLabel: "clearButtonLabel", signDocumentButtonLabel: "signDocumentButtonLabel", cancelButtonLabel: "cancelButtonLabel" }, outputs: { pdfSaved: "pdfSaved", cancelClick: "cancelClick" }, host: { properties: { "class.co-docsign": "this.showClass" } }, viewQueries: [{ propertyName: "pdfContainer", first: true, predicate: ["pdfContainer"], descendants: true, read: ElementRef }], ngImport: i0, template: `
526
+ <div #pdfContainer class="pdf-container"></div>
521
527
  @if (showSignatures) {
522
528
  <co-signatures @showHideSignature
523
529
  [showFirstSignature]="showSigBuyer"
@@ -553,7 +559,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
553
559
  args: [{
554
560
  selector: "co-docsign",
555
561
  template: `
556
- <iframe #iframe></iframe>
562
+ <div #pdfContainer class="pdf-container"></div>
557
563
  @if (showSignatures) {
558
564
  <co-signatures @showHideSignature
559
565
  [showFirstSignature]="showSigBuyer"
@@ -587,9 +593,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
587
593
  encapsulation: ViewEncapsulation.None,
588
594
  standalone: false
589
595
  }]
590
- }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }], propDecorators: { iframe: [{
596
+ }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }], propDecorators: { pdfContainer: [{
591
597
  type: ViewChild,
592
- args: ["iframe", { read: ElementRef }]
598
+ args: ['pdfContainer', { read: ElementRef }]
593
599
  }], pdf: [{
594
600
  type: Input
595
601
  }], firstSignatureLabel: [{