import { useEffect, useState } from 'react';
import { Viewer, DocumentGate, pageRefsEqual } from '@embedpdf/react/runtime';
import type { OpenInput, PageContextValue, PageRef } from '@embedpdf/react/runtime';
import { Stage, stagePlugin } from '@embedpdf/react/stage';
import { RenderLayer, renderPlugin } from '@embedpdf/react/render';
import {
interactionPlugin,
svgCursor,
useInteraction,
useInteractionState,
} from '@embedpdf/react/interaction';
import { cloudEngine } from '@cloudpdf/engine';
import './pin.css';
const engine = cloudEngine();
const plugins = [stagePlugin(), renderPlugin(), interactionPlugin()];
const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' };
interface Pin {
readonly id: number;
readonly page: PageRef;
readonly point: { readonly x: number; readonly y: number };
}
// The cursor is the pin itself; its tip is the point that clicks.
const PIN_CURSOR = svgCursor({
svg: ``,
hotspot: { x: 12, y: 23 },
fallback: 'copy',
});
// The pins on one page, placed in its pixels at the last moment.
function PinLayer({ page, pins }: { page: PageContextValue; pins: readonly Pin[] }) {
return (
<>
{pins
.filter((pin) => pageRefsEqual(pin.page, page.ref))
.map((pin) => {
const { x, y } = page.transform.toPixels(pin.point);
return (
{pin.id}
);
})}
>
);
}
function PinBoard() {
const interaction = useInteraction();
const { activeToolId } = useInteractionState();
const [pins, setPins] = useState