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 { localEngine } from '@embedpdf/engine';
import './label.css';
const engine = localEngine();
// 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' } } }),
];
// [!doc-source welcome]
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()) };
};
// [!/doc-source]
// 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 (
);
}
export default function App() {
return (
Loading…
}>
{() => (
<>
>
)}
);
}