import { ChangeDetectionStrategy, Component, computed, effect, inject, input, 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 { EpdfSelectionLayer, withSelection } from '@embedpdf/angular/selection'; import { withInteraction } from '@embedpdf/angular/interaction'; import { EpdfAnnotationLayer, withAnnotation } from '@embedpdf/angular/annotation'; import { EpdfStamp, withStamp, type StampAsset } from '@embedpdf/angular/stamp'; import { LOCALES, loadDefaultLibrary } from '@embedpdf/default-stamps/library'; import { cloudEngine } from '@cloudpdf/engine'; import { localEngine } from '@embedpdf/engine'; const engine = cloudEngine(); const assetEngine = localEngine(); const approvals: OpenInput = { kind: 'grant', grant: 'shr_lu5Sb4r9PYjKrHS3qfNeUywM' }; @Component({ selector: 'button[demoStampButton]', changeDetection: ChangeDetectionStrategy.OnPush, host: { type: 'button', class: 'button', '[title]': 'asset().label', '[attr.aria-pressed]': 'armed()', '(click)': 'toggle()', }, template: ` @if (url(); as url) { } @else { {{ asset().label }} } `, }) export class StampButton { readonly asset = input.required(); readonly armed = input(false); private readonly stamp = inject(EpdfStamp); protected readonly url = this.stamp.previewUrlOf(() => this.asset().id); protected toggle() { if (this.armed()) this.stamp.disarm(); else void this.stamp.armAsset(this.asset().id); } } @Component({ selector: 'demo-language-picker', imports: [StampButton], changeDetection: ChangeDetectionStrategy.OnPush, template: `
@for (asset of shown(); track asset.id) { } {{ library()?.name ?? 'Loading…' }}
`, }) export class LanguagePicker { private readonly stamp = inject(EpdfStamp); protected readonly locales = LOCALES; protected readonly locale = signal('nl'); protected readonly library = computed(() => this.stamp.libraries()[0]); private readonly assets = this.stamp.assetsOf(() => ({ libraryId: this.library()?.id })); protected readonly shown = computed(() => this.assets().slice(0, 4)); protected readonly armedAsset = this.stamp.armedAsset; constructor() { // The library of the chosen language replaces the one before: the same identifiers, // translated labels. Dutch on load. effect((onCleanup) => { const locale = this.locale(); let current = true; onCleanup(() => (current = false)); void loadDefaultLibrary(locale).then(async (bytes) => { if (!current) return; for (const old of this.stamp.listLibraries()) await this.stamp.deleteLibrary(old.id); if (current) await this.stamp.importLibrary(bytes); }); }); } } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSelectionLayer, EpdfAnnotationLayer, LanguagePicker, ], providers: [ provideEmbedPdf( { engine, initialDocuments: [{ source: approvals }] }, withStage(), withRender(), withInteraction(), withSelection(), withAnnotation(), withStamp({ assetEngine }), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './languages.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}