import { useEffect, useRef } from 'react';
import { Viewer, DocumentGate, usePageList } from '@embedpdf/react/runtime';
import type { OpenInput } from '@embedpdf/react/runtime';
import { Stage, stagePlugin, useStage } from '@embedpdf/react/stage';
import { RenderLayer, renderPlugin } from '@embedpdf/react/render';
import { interactionPlugin } from '@embedpdf/react/interaction';
import {
AnnotationLayer,
annotationPlugin,
useAnnotation,
useAnnotationState,
} from '@embedpdf/react/annotation';
import { localEngine } from '@embedpdf/engine';
import './select-code.css';
const engine = localEngine();
const plugins = [stagePlugin(), renderPlugin(), interactionPlugin(), annotationPlugin()];
// [!doc-source layout]
const layout = async (): Promise => {
const response = await fetch('https://www.embedpdf.com/pdfs/layout.pdf');
return { kind: 'bytes', id: 'layout', bytes: new Uint8Array(await response.arrayBuffer()) };
};
// [!/doc-source]
// The top half of a page, where the box selects: on the home page, the image and the button.
const TOP_HALF = { x: 0, y: 0, width: 612, height: 396 };
// On load: the home page wireframe, with everything on it selected.
function SelectShapes() {
const annotation = useAnnotation();
const stage = useStage();
const ready = useAnnotationState((state) => state.status === 'ready');
const page = usePageList()[0]?.ref;
const done = useRef(false);
useEffect(() => {
if (!ready || !page || done.current) return;
done.current = true;
annotation.selection.selectAll(page);
stage.goToPage(page);
}, [annotation, stage, ready, page]);
return null;
}
function SelectionToolbar() {
const annotation = useAnnotation();
const { selected } = useAnnotationState(); // the selected annotations
const page = usePageList()[0]?.ref; // the home page wireframe
return (
);
}
export default function App() {
return (
Loading…
}>
{() => (
<>
>
)}
);
}