import { useEffect, useState } from 'react'; import { Viewer, DocumentGate } from '@embedpdf/react/runtime'; import type { OpenInput } from '@embedpdf/react/runtime'; import { Stage, stagePlugin } from '@embedpdf/react/stage'; import { RenderLayer, renderPlugin } from '@embedpdf/react/render'; import { SelectionLayer, selectionPlugin } from '@embedpdf/react/selection'; import { interactionPlugin } from '@embedpdf/react/interaction'; import { AnnotationLayer, annotationPlugin } from '@embedpdf/react/annotation'; import { stampPlugin, useStamp, useStampAssetPreviewUrl, useStampAssets, useStampLibraries, useStampState, } from '@embedpdf/react/stamp'; import type { StampAsset } from '@embedpdf/react/stamp'; import { LOCALES, loadDefaultLibrary } from '@embedpdf/default-stamps/library'; import { cloudEngine } from '@cloudpdf/engine'; import { localEngine } from '@embedpdf/engine'; import './languages.css'; const engine = cloudEngine(); const assetEngine = localEngine(); const plugins = [ stagePlugin(), renderPlugin(), interactionPlugin(), selectionPlugin(), annotationPlugin(), stampPlugin({ assetEngine }), ]; const approvals: OpenInput = { kind: 'grant', grant: 'shr_lu5Sb4r9PYjKrHS3qfNeUywM' }; function StampButton({ asset, armed }: { asset: StampAsset; armed: boolean }) { const stamp = useStamp(); const url = useStampAssetPreviewUrl(asset.id); return ( ); } function LanguagePicker() { const stamp = useStamp(); const [library] = useStampLibraries(); const assets = useStampAssets({ libraryId: library?.id }); const { armedAsset } = useStampState(); const [locale, setLocale] = useState('nl'); // The library of the chosen language replaces the one before: the same // identifiers, translated labels. Dutch on load. useEffect(() => { let current = true; void loadDefaultLibrary(locale).then(async (bytes) => { if (!current) return; for (const old of stamp.listLibraries()) await stamp.deleteLibrary(old.id); if (current) await stamp.importLibrary(bytes); }); return () => { current = false; }; }, [stamp, locale]); return (