import { useEffect, useRef, useState } from 'react';
import { Viewer, DocumentGate, saveFile, useDocuments } 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 { AnnotationLayer, annotationPlugin, useAnnotationState } from '@embedpdf/react/annotation';
import { redactionPlugin, useRedaction, useRedactionState } from '@embedpdf/react/redaction';
import { localEngine } from '@embedpdf/engine';
import './apply.css';
const engine = localEngine();
const plugins = [
stagePlugin(),
renderPlugin(),
interactionPlugin(),
annotationPlugin(),
redactionPlugin(),
];
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()) };
};
// The cover's title, in page coordinates: the shapes drawn over it go with it.
const TITLE = { x: 100, y: 212, width: 392, height: 156 };
function ApplyBar() {
const redaction = useRedaction();
const documents = useDocuments();
const { pendingCount, applying, lastResult } = useRedactionState();
const ready = useAnnotationState((state) => state.status === 'ready');
const [asking, setAsking] = useState(false);
const started = useRef(false);
// On load: the title marked.
useEffect(() => {
if (!ready || started.current) return;
started.current = true;
void redaction.markArea(0, TITLE);
}, [redaction, ready]);
// The other annotations applying removes too: they could show what was there.
const { count } = redaction.estimateCollateral();
if (asking) {
return (
Redact {pendingCount} {pendingCount === 1 ? 'mark' : 'marks'}?{' '}
{count > 0 &&
`${count} ${count === 1 ? 'annotation' : 'annotations'} under them go too. `}
This can’t be undone.
);
}
return (
);
}
export default function App() {
return (
Loading…
}>
{() => (
<>
>
)}
);
}