import { 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 { interactionPlugin, useInteraction } from '@embedpdf/react/interaction'; import { SelectionLayer, selectionPlugin } from '@embedpdf/react/selection'; import { AnnotationLayer, annotationPlugin } from '@embedpdf/react/annotation'; import { commandsPlugin, standardCommands } from '@embedpdf/react/commands'; import type { ResolvedCommand } from '@embedpdf/react/commands'; import { Toolbar, group } from '@embedpdf/react/toolbar'; import type { BarSchema } from '@embedpdf/react/toolbar'; import { localEngine } from '@embedpdf/engine'; import './modes.css'; const engine = localEngine(); const plugins = [ stagePlugin(), renderPlugin(), interactionPlugin(), selectionPlugin(), annotationPlugin(), commandsPlugin({ commands: standardCommands }), ]; // [!doc-source welcome] const welcome = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/welcome.pdf'); return { kind: 'bytes', id: 'welcome', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] // A bar per mode. const viewBar: BarSchema = { id: 'view', sections: { start: [group('tools', ['tool:pointer', 'tool:pan'])], center: [ group('pages', ['page:previous', 'page:next']), group('zoom', ['zoom:out', 'zoom:in']), ], }, }; const annotateBar: BarSchema = { id: 'annotate', sections: { start: [group('markup', ['tool:highlight', 'tool:underline', 'tool:strikeout'])], center: [group('draw', ['tool:ink', 'tool:square', 'tool:circle', 'tool:note'])], end: [group('edit', ['annotation:delete'])], }, }; type Mode = 'view' | 'annotate'; const BARS: Record = { view: viewBar, annotate: annotateBar }; const TOOL_OF_MODE: Record = { view: 'pointer', annotate: 'highlight' }; const renderCommand = (command: ResolvedCommand, _variant: string, run: () => void) => ( ); function ModeToolbar() { const interaction = useInteraction(); const [mode, setMode] = useState('view'); // Each mode starts with its own tool. const switchTo = (next: Mode) => { setMode(next); interaction.activateTool(TOOL_OF_MODE[next]); }; return (
{(['view', 'annotate'] as const).map((each) => ( ))}
); } export default function App() { return ( Loading…

}> {() => ( <> )}
); }