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 { localEngine } from '@embedpdf/engine';
import './languages.css';
const engine = localEngine();
const assetEngine = engine; // stamp libraries are PDFs; they open here too
const plugins = [
stagePlugin(),
renderPlugin(),
interactionPlugin(),
selectionPlugin(),
annotationPlugin(),
stampPlugin({ assetEngine }),
];
const approvals = async (): Promise => {
const response = await fetch('https://www.embedpdf.com/pdfs/approvals.pdf');
return { kind: 'bytes', id: 'approvals', bytes: new Uint8Array(await response.arrayBuffer()) };
};
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 (
{assets.slice(0, 4).map((asset) => (
))}
);
}
export default function App() {
return (
Loading…
}>
{() => (
<>
>
)}
);
}