import { useEffect, useState } from 'react';
import { Viewer, DocumentGate } from '@embedpdf/react/runtime';
import type { OpenInput, PageRef } from '@embedpdf/react/runtime';
import { Stage, stagePlugin, useStage, useStageState } from '@embedpdf/react/stage';
import type { StageViewState, Viewpoint } from '@embedpdf/react/stage';
import { RenderLayer, renderPlugin } from '@embedpdf/react/render';
import { localEngine } from '@embedpdf/engine';
import './viewpoint.css';
const engine = localEngine();
const plugins = [stagePlugin(), renderPlugin()];
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()) };
};
function Memory() {
const stage = useStage();
const { currentPageIndex, zoomLevel } = useStageState();
// One spot on one page, and the whole view: settings and position.
const [spot, setSpot] = useState<{ page: PageRef; viewpoint: Viewpoint; label: string } | null>(
null,
);
const [view, setView] = useState(null);
const rememberSpot = () => {
const page = stage.getCurrentPage();
if (!page) return;
const label = `page ${stage.getCurrentPageIndex() + 1}`;
setSpot({ page, viewpoint: stage.getViewpoint(), label });
};
// Remember where the reader starts, so "Go back" works right away.
useEffect(rememberSpot, [stage]);
return (
);
}
export default function App() {
return (
Loading…
}>
{() => }
);
}