import { ChangeDetectionStrategy, Component, computed, effect, inject, signal, ViewEncapsulation, } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { EpdfDocument, EpdfDocumentGate, EpdfDocuments, provideEmbedPdf, saveFile, } from '@embedpdf/angular/runtime'; import type { OpenInput } from '@embedpdf/angular/runtime'; import { EpdfPageTemplate, EpdfStage, withStage } from '@embedpdf/angular/stage'; import { EpdfRenderLayer, withRender } from '@embedpdf/angular/render'; import { EpdfMetadata, withMetadata } from '@embedpdf/angular/metadata'; import { cloudEngine } from '@cloudpdf/engine'; const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' }; @Component({ selector: 'demo-title-bar', changeDetection: ChangeDetectionStrategy.OnPush, template: `
`, }) export class TitleBar { private readonly documents = inject(EpdfDocuments); protected readonly document = inject(EpdfDocument); protected readonly metadata = inject(EpdfMetadata); protected readonly title = computed(() => this.metadata.fields()?.title ?? ''); constructor() { // A change on load: the document gets a new title, so it has something to lose. void this.metadata.update({ title: 'Documents belong on the web (draft)' }); // While there's something to lose, the browser asks before the page closes. effect((onCleanup) => { if (!this.document.hasUnsavedChanges()) return; const warn = (event: BeforeUnloadEvent) => event.preventDefault(); window.addEventListener('beforeunload', warn); onCleanup(() => window.removeEventListener('beforeunload', warn)); }); } protected async download() { saveFile(await this.documents.download(), 'welcome.pdf'); } } @Component({ selector: 'demo-change-log', changeDetection: ChangeDetectionStrategy.OnPush, template: `Opening…