import { useEffect, useState, type CSSProperties } 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, useInteractionState, } from '@embedpdf/react/interaction'; import { AnnotationLayer, annotationPlugin } from '@embedpdf/react/annotation'; import { localEngine } from '@embedpdf/engine'; import './ghost.css'; const engine = localEngine(); // A preview for the rectangle (off by default for tools you drag), and a fainter one for notes. const plugins = [ stagePlugin(), renderPlugin(), interactionPlugin(), annotationPlugin({ tools: [ { id: 'square', ghost: true }, { id: 'note', ghost: { opacity: 0.3 } }, ], }), ]; // [!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: 'note', label: 'Note' }, { id: 'square', label: 'Rectangle' }, ]; function Toolbar({ opacity, onOpacity, }: { opacity: number | null; onOpacity: (value: number | null) => void; }) { const interaction = useInteraction(); const { activeToolId } = useInteractionState(); // The note tool is active on load: move the pointer over the page. useEffect(() => { interaction.activateTool('note'); }, [interaction]); return (
{TOOLS.map((tool) => ( ))}
); } export default function App() { // `--epdf-ghost-opacity` from CSS wins over each tool's own opacity, for every tool. const [opacity, setOpacity] = useState(null); const ghostOpacity = opacity === null ? undefined : { '--epdf-ghost-opacity': opacity }; return ( Loading…

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