();
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) {
}
`,
})
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 {}