import { useEffect } 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, useToolCursor, } from '@embedpdf/react/interaction'; import { AnnotationLayer, annotationPlugin, useAnnotation, useAnnotationDefaults, } from '@embedpdf/react/annotation'; import { localEngine } from '@embedpdf/engine'; import './cursor.css'; const engine = localEngine(); // A standard cursor for the rectangle tool: any CSS cursor name. const plugins = [ stagePlugin(), renderPlugin(), interactionPlugin(), annotationPlugin({ tools: [{ id: 'square', cursor: 'cell' }] }), ]; // [!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] // A pen, 24 Ă— 24, in a color: its tip is the bottom-left corner. const penIcon = (color: string) => `` + `` + ``; // The pen cursor follows the pen's color. function InkCursor() { const { color } = useAnnotationDefaults('ink'); useToolCursor({ toolId: 'ink', cursors: { crosshair: { svg: penIcon(color ?? '#000000'), hotspot: { x: 2, y: 22 } } }, }); return null; } const COLORS = ['#e5484d', '#1e90ff', '#30a46c', '#1a2748']; function Toolbar() { const annotation = useAnnotation(); const interaction = useInteraction(); const { activeToolId } = useInteractionState(); const { color } = useAnnotationDefaults('ink'); // The pen is active on load: move the pointer over the page. useEffect(() => { interaction.activateTool('ink'); }, [interaction]); return (
{COLORS.map((swatch) => (
); } export default function App() { return ( Loading…

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