import { ChangeDetectionStrategy, Component, computed, inject, signal, 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 { withInteraction } from '@embedpdf/angular/interaction'; import { EpdfCommand, EpdfCommands, standardCommands, withCommands, } from '@embedpdf/angular/commands'; import { localEngine } from '@embedpdf/engine'; // [!doc-source welcome] const welcome = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/welcome.pdf'); return { kind: 'bytes', id: 'welcome', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] @Component({ selector: 'div[demoCommandPalette]', imports: [EpdfCommand], changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'palette' }, template: ` `, }) export class CommandPalette { private readonly commands = inject(EpdfCommands); protected readonly query = signal('page'); protected readonly results = computed(() => this.commands.searchCommands(this.query())); // Enter runs the first result that can run now. protected runFirst() { const first = this.results().find((command) => this.commands.canExecute(command.id)); if (first) void this.commands.execute(first.id); } } @Component({ selector: 'demo-root', imports: [EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, CommandPalette], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), withInteraction(), withCommands({ commands: standardCommands }), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './palette.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}