import { 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 { SelectionLayer, selectionPlugin } from '@embedpdf/react/selection';
import { interactionPlugin } from '@embedpdf/react/interaction';
import {
AnnotationLayer,
annotationPlugin,
type AnnotationRenderer,
type AnnotationRendererProps,
} from '@embedpdf/react/annotation';
import { localEngine } from '@embedpdf/engine';
import './renderers.css';
const engine = localEngine();
const plugins = [
stagePlugin(),
renderPlugin(),
interactionPlugin(),
selectionPlugin(),
annotationPlugin(),
];
const proposal = async (): Promise => {
const response = await fetch('https://www.embedpdf.com/pdfs/proposal.pdf');
return { kind: 'bytes', id: 'proposal', bytes: new Uint8Array(await response.arrayBuffer()) };
};
// A note drawn as your app's comment bubble, the author's initials in it and its
// text in the tooltip. It fills its frame, so the selection outline and the click
// area match it, and it turns with the annotation: a note stays upright on a turned
// page.
function CommentBubble({ annotation, hovered }: AnnotationRendererProps) {
const initials = (annotation.author ?? '?')
.split(' ')
.map((word) => word[0])
.join('');
return (
{initials}
);
}
// Defined once, outside the component: the layer registers each entry.
const RENDERERS: AnnotationRenderer[] = [
{ for: (annotation) => annotation.subtype === 'text', component: CommentBubble },
];
const NONE: AnnotationRenderer[] = [];
// A note keeps its size on screen and stays upright: turn the view to see it.
function TurnButton() {
const stage = useStage();
return (
);
}
export default function App() {
const [mine, setMine] = useState(true);
return (
Loading…