import { useEffect, useRef, 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, useInteraction, useToolCursor } from '@embedpdf/react/interaction';
import { cloudEngine } from '@cloudpdf/engine';
import './cursor.css';
const engine = cloudEngine();
const plugins = [stagePlugin(), renderPlugin(), interactionPlugin()];
const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' };
const COLORS = ['#e5484d', '#2f80ed', '#30a46c', '#1a2748'];
// A pen in the current color, with its tip at the bottom left.
const penIcon = (color: string) =>
``;
interface Dot {
readonly id: number;
readonly page: PageRef;
readonly point: { readonly x: number; readonly y: number };
readonly color: string;
}
// While this is mounted, the dot tool's crosshair is a pen in `color`.
function PenCursor({ color }: { color: string }) {
useToolCursor({
toolId: 'dot',
cursors: { crosshair: { svg: penIcon(color), hotspot: { x: 3, y: 21 } } },
});
return null;
}
function DotLayer({ page, dots }: { page: PageContextValue; dots: readonly Dot[] }) {
return (
<>
{dots
.filter((dot) => pageRefsEqual(dot.page, page.ref))
.map((dot) => {
const { x, y } = page.transform.toPixels(dot.point);
return (
);
})}
>
);
}
function Dots() {
const interaction = useInteraction();
const [color, setColor] = useState(COLORS[0]);
const [penCursor, setPenCursor] = useState(true);
const [dots, setDots] = useState