import { useEffect, useRef, useState } from 'react'; import { Viewer, DocumentGate } 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, useAnnotationState } from '@embedpdf/react/annotation'; import { redactionPlugin, usePendingRedactions, useRedaction, useRedactionState, } from '@embedpdf/react/redaction'; import { cloudEngine } from '@cloudpdf/engine'; import './label.css'; const engine = cloudEngine(); // What applying paints over every mark: a dark blue area, its label in white. const plugins = [ stagePlugin(), renderPlugin(), interactionPlugin(), annotationPlugin(), redactionPlugin({ overlay: { fill: '#1a2748', text: { color: '#ffffff' } } }), ]; const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' }; // The cover's subtitle, in page coordinates. const SUBTITLE = { x: 100, y: 378, width: 352, height: 114 }; function LabelBar() { const redaction = useRedaction(); const stage = useStage(); const { applying, lastResult } = useRedactionState(); const [mark] = usePendingRedactions(); const ready = useAnnotationState((state) => state.status === 'ready'); const [text, setText] = useState('Classified'); const started = useRef(false); // On load: the subtitle marked, with a label that fills the area. useEffect(() => { if (!ready || started.current) return; started.current = true; void redaction .markArea(0, SUBTITLE) .then(({ mark }) => redaction.updateLabel(mark.ref, { overlayText: 'Classified', repeat: true }), ) .then(() => stage.reveal(0, { rect: SUBTITLE })); }, [redaction, stage, ready]); return (
{ event.preventDefault(); if (mark) void redaction.updateLabel(mark.ref, { overlayText: text.trim() || null }); }} > setText(event.target.value)} />
{lastResult ? 'The label is part of the page now' : 'Redact to see the label'}
); } export default function App() { return ( Loading…

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