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 {
interactionPlugin,
useInteraction,
useInteractionState,
} from '@embedpdf/react/interaction';
import {
AnnotationLayer,
annotationKey,
annotationPlugin,
useAnnotationList,
} from '@embedpdf/react/annotation';
import { localEngine } from '@embedpdf/engine';
import './identity.css';
const engine = localEngine();
const plugins = [stagePlugin(), renderPlugin(), interactionPlugin(), annotationPlugin()];
// [!doc-source sketch]
const sketch = async (): Promise => {
const response = await fetch('https://www.embedpdf.com/pdfs/sketch.pdf');
return { kind: 'bytes', id: 'sketch', bytes: new Uint8Array(await response.arrayBuffer()) };
};
// [!/doc-source]
const TOOLS = [
{ id: 'pointer', label: 'Select' },
{ id: 'square', label: 'Rectangle' },
{ id: 'note', label: 'Note' },
];
function Toolbar() {
const interaction = useInteraction();
const { activeToolId } = useInteractionState();
return (
{TOOLS.map((tool) => (
interaction.activateTool(tool.id)}
>
{tool.label}
))}
);
}
const time = (date: string | null) =>
date ? new Date(date).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) : '';
// Who wrote each annotation, and when: the engine fills these in from the identity.
function Authors() {
const annotations = useAnnotationList();
return (
{annotations.length === 0 && Draw something }
{annotations.map((annotation) => (
{annotation.subtype}
{annotation.author ?? 'Nobody'} · {time(annotation.createdAt)}
))}
);
}
export default function App() {
return (
Loading…
}>
);
}