import { useEffect, useState } 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 { SelectionHandles, SelectionLayer, selectionPlugin, useSelection, useSelectionSettings, } from '@embedpdf/react/selection'; import { localEngine } from '@embedpdf/engine'; import './colors.css'; const engine = localEngine(); const plugins = [ stagePlugin(), renderPlugin(), interactionPlugin(), selectionPlugin({ handles: { shadow: '0 1px 3px rgb(0 0 0 / 0.3)' } }), ]; // Each: the selected text and its handles. `null` is the viewer's accent: at 35% for the text. const COLORS = [ { name: 'Accent', color: null, handles: null, swatch: '#3858e9' }, { name: 'Yellow', color: 'rgb(250 204 21 / 0.45)', handles: '#ca8a04', swatch: '#facc15' }, { name: 'Green', color: 'rgb(34 197 94 / 0.35)', handles: '#16a34a', swatch: '#22c55e' }, { name: 'Pink', color: 'rgb(236 72 153 / 0.3)', handles: '#db2777', swatch: '#ec4899' }, ]; 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 ColorPicker() { const selection = useSelection(); const current = useSelectionSettings((settings) => settings.color); return ( <> {COLORS.map(({ name, color, handles, swatch }) => ( ); } // 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() { const [fromCss, setFromCss] = useState(false); return ( Loading…

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