import { useState } from 'react'; import { Viewer, DocumentGate } from '@embedpdf/react/runtime'; import type { OpenInput } from '@embedpdf/react/runtime'; import { Stage, stagePlugin, useStage, useStageSettings, useStageState, } from '@embedpdf/react/stage'; import { RenderLayer, renderPlugin } from '@embedpdf/react/render'; import { localEngine } from '@embedpdf/engine'; import './responsive.css'; const engine = localEngine(); // Facing pages with a roomy margin, and one rule for a narrow Stage: a thin // margin and one page at a time. The rule has a name, so the UI can read it too. const plugins = [ stagePlugin({ padding: 24, spread: 'odd', responsive: [ { name: 'compact', when: { maxWidth: 600 }, settings: { padding: 4, spread: 'none' } }, ], }), 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 Toolbar({ narrow, onNarrow }: { narrow: boolean; onNarrow: (narrow: boolean) => void }) { const stage = useStage(); // One breakpoint drives both the layout and this toolbar. const compact = useStageState((state) => state.activeRules.includes('compact')); const { padding, spread } = useStageSettings(); return (
compact {compact ? 'on' : 'off'} padding {typeof padding === 'number' ? padding : 'by side'} · spread{' '} {spread}
); } export default function App() { const [narrow, setNarrow] = useState(false); return ( Loading…

}>
{() => }
); }