'use client'; import type { PDFDocumentProxy } from 'pdfjs-dist'; import { useMemo, useState } from 'react'; import { Document, Page } from 'react-pdf'; import useWindowSize from '@/hooks/useWindowSize'; import { graphLightT } from '@/styling/color'; import Overlay from '../Overlay'; import PageControls from './PageControls'; const MAXIMUM_WIDTH = 1000; const MINIMUM_WIDTH = 300; interface PDFViewerProps { file?: string | ArrayBuffer | Blob; offsetXpx?: number; minWidth?: number; } function PDFViewer({ file, offsetXpx, minWidth = MINIMUM_WIDTH }: PDFViewerProps) { const windowSize = useWindowSize(); const [pageCount, setPageCount] = useState(0); const [pageNumber, setPageNumber] = useState(1); const pageWidth = useMemo(() => { return Math.max(minWidth, Math.min((windowSize?.width ?? 0) - (offsetXpx ?? 0) - 10, MAXIMUM_WIDTH)); }, [windowSize, offsetXpx, minWidth]); function onDocumentLoadSuccess({ numPages }: PDFDocumentProxy) { setPageCount(numPages); } return ( ); } export default PDFViewer;