import { ChangeDetectionStrategy, Component, inject, ViewEncapsulation } from '@angular/core'; import { EpdfDocumentGate, provideEmbedPdf } 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 { EpdfSelectionLayer, withSelection } from '@embedpdf/angular/selection'; import { withInteraction } from '@embedpdf/angular/interaction'; import { EpdfAnchored } from '@embedpdf/angular/anchored'; import { EpdfAnnotation, EpdfAnnotationLayer, withAnnotation } from '@embedpdf/angular/annotation'; import { localEngine } from '@embedpdf/engine'; // [!doc-source proposal] const proposal = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/proposal.pdf'); return { kind: 'bytes', id: 'proposal', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] // A card next to the annotation under the pointer: who wrote it, and what. @Component({ selector: 'demo-hover-card', imports: [EpdfAnchored], changeDetection: ChangeDetectionStrategy.OnPush, template: ` @if (hovered(); as hovered) { @if (hovered.contents) {
{{ hovered.author ?? 'Someone' }}

{{ hovered.contents }}

} } `, }) export class HoverCard { private readonly annotation = inject(EpdfAnnotation); protected readonly hovered = this.annotation.hovered; // the annotation under the pointer, or null protected readonly anchor = this.annotation.anchorOf(() => this.hovered()?.ref ?? null); } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSelectionLayer, EpdfAnnotationLayer, HoverCard, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), identity: { userId: 'u_381', displayName: 'Dana Smith' }, initialDocuments: [{ source: proposal }], }, withStage(), withRender(), withInteraction(), withSelection(), withAnnotation(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './hover-card.css', encapsulation: ViewEncapsulation.None, template: `

Point at a note or a marked sentence

Loading…

`, }) export class App {}