import type { FC } from 'react' import { Dialog, DialogContent } from '@langgenius/dify-ui/dialog' import { Tooltip, TooltipContent, TooltipTrigger } from '@langgenius/dify-ui/tooltip' import { RiCloseLine, RiZoomInLine, RiZoomOutLine } from '@remixicon/react' import { noop } from 'es-toolkit/function' import { useState } from 'react' import { useHotkeys } from 'react-hotkeys-hook' import { useTranslation } from 'react-i18next' import Loading from '@/app/components/base/loading' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import { PdfHighlighter, PdfLoader } from './pdf-highlighter-adapter' type PdfPreviewProps = { url: string onCancel: () => void } const PdfPreview: FC = ({ url, onCancel, }) => { const { t } = useTranslation() const media = useBreakpoints() const [scale, setScale] = useState(1) const [position, setPosition] = useState({ x: 0, y: 0 }) const isMobile = media === MediaType.mobile const zoomIn = () => { setScale(prevScale => Math.min(prevScale * 1.2, 15)) setPosition({ x: position.x - 50, y: position.y - 50 }) } const zoomOut = () => { setScale((prevScale) => { const newScale = Math.max(prevScale / 1.2, 0.5) if (newScale === 1) setPosition({ x: 0, y: 0 }) else setPosition({ x: position.x + 50, y: position.y + 50 }) return newScale }) } useHotkeys('up', zoomIn) useHotkeys('down', zoomOut) const zoomOutLabel = t('operation.zoomOut', { ns: 'common' }) const zoomInLabel = t('operation.zoomIn', { ns: 'common' }) const cancelLabel = t('operation.cancel', { ns: 'common' }) return ( { if (!open) onCancel() }} disablePointerDismissal >
e.stopPropagation()} className="h-[95vh] max-h-full w-screen max-w-full overflow-hidden" style={{ transform: `scale(${scale})`, transformOrigin: 'center', scrollbarWidth: 'none', msOverflowStyle: 'none' }} >
} > {(pdfDocument) => { return ( event.altKey} scrollRef={noop} onScrollChange={noop} onSelectionFinished={() => null} highlightTransform={() => { return
}} highlights={[]} /> ) }}
)} /> {zoomOutLabel} )} /> {zoomInLabel} )} /> {cancelLabel}
) } export default PdfPreview