import { useEffect } from 'react'; import { Viewer, DocumentGate, usePageList } 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 } from '@embedpdf/react/interaction'; import { SelectionLayer, selectionPlugin, useSelection, useSelectionState, } from '@embedpdf/react/selection'; import { localEngine } from '@embedpdf/engine'; import './state.css'; const engine = localEngine(); const plugins = [stagePlugin(), renderPlugin(), interactionPlugin(), selectionPlugin()]; 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()) }; }; // Every field of the selection's state, as it changes. function SelectionStatus() { const { hasSelection, isSelecting, range, pages } = useSelectionState(); return (
hasSelection
{String(hasSelection)}
isSelecting
{String(isSelecting)}
pages
{pages.length === 1 ? '1 page' : `${pages.length} pages`}
range
{range ? `${range.start.index} → ${range.end.index}` : 'null'}
); } // Something selected on load: "Documents", the first word on the cover. function SelectTitle() { const selection = useSelection(); const cover = usePageList()[0]?.ref; useEffect(() => { if (cover) selection.select({ page: cover, start: 28, count: 9 }); }, [selection, cover]); return null; } export default function App() { return ( Loading…

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