@@ -53,26 +53,14 @@ function MediaViewer({ path, type, onClose }: { path: string; type: "video" | "a
5353}
5454
5555function PdfViewer ( { path, onClose } : { path : string ; onClose : ( ) => void } ) {
56- const [ zoom , setZoom ] = useState ( 1 ) ;
57- const lastDistance = useRef ( 0 ) ;
56+ const [ zoomPct , setZoomPct ] = useState ( 100 ) ;
5857
59- const zoomIn = ( ) => setZoom ( ( z ) => Math . min ( 5 , z + 0. 25) ) ;
60- const zoomOut = ( ) => setZoom ( ( z ) => Math . max ( 0. 25, z - 0. 25) ) ;
61- const zoomFit = ( ) => setZoom ( 1 ) ;
58+ const zoomIn = ( ) => setZoomPct ( ( z ) => Math . min ( 500 , z + 25 ) ) ;
59+ const zoomOut = ( ) => setZoomPct ( ( z ) => Math . max ( 25 , z - 25 ) ) ;
60+ const zoomFit = ( ) => setZoomPct ( 100 ) ;
6261
63- const handleTouchMove = ( e : React . TouchEvent ) => {
64- if ( e . touches . length !== 2 ) return ;
65- const dx = e . touches [ 0 ] . clientX - e . touches [ 1 ] . clientX ;
66- const dy = e . touches [ 0 ] . clientY - e . touches [ 1 ] . clientY ;
67- const dist = Math . sqrt ( dx * dx + dy * dy ) ;
68- if ( lastDistance . current > 0 ) {
69- const delta = ( dist - lastDistance . current ) * 0.005 ;
70- setZoom ( ( z ) => Math . max ( 0.25 , Math . min ( 5 , z + delta ) ) ) ;
71- }
72- lastDistance . current = dist ;
73- } ;
74-
75- const handleTouchEnd = ( ) => { lastDistance . current = 0 ; } ;
62+ // Use PDF viewer's built-in zoom via URL fragment
63+ const pdfUrl = `/api/files/download?path=${ encodeURIComponent ( path ) } &inline=1#zoom=${ zoomPct } ` ;
7664
7765 return (
7866 < div className = "flex flex-col h-full" >
@@ -81,7 +69,7 @@ function PdfViewer({ path, onClose }: { path: string; onClose: () => void }) {
8169 < div className = "flex items-center gap-2" >
8270 < div className = "flex items-center gap-1 border border-gray-700 rounded overflow-hidden" >
8371 < button onClick = { zoomOut } className = "px-2 py-0.5 text-xs text-gray-400 hover:text-white hover:bg-gray-700" > -</ button >
84- < button onClick = { zoomFit } className = "px-2 py-0.5 text-[10px] text-gray-400 hover:text-white hover:bg-gray-700 tabular-nums" > { Math . round ( zoom * 100 ) } %</ button >
72+ < button onClick = { zoomFit } className = "px-2 py-0.5 text-[10px] text-gray-400 hover:text-white hover:bg-gray-700 tabular-nums" > { zoomPct } %</ button >
8573 < button onClick = { zoomIn } className = "px-2 py-0.5 text-xs text-gray-400 hover:text-white hover:bg-gray-700" > +</ button >
8674 </ div >
8775 < a
@@ -101,27 +89,12 @@ function PdfViewer({ path, onClose }: { path: string; onClose: () => void }) {
10189 </ button >
10290 </ div >
10391 </ div >
104- < div
105- className = "flex-1 min-h-0 overflow-auto bg-[#0d0d1a] relative"
106- onTouchMove = { handleTouchMove }
107- onTouchEnd = { handleTouchEnd }
108- >
109- { /* Spacer to create scrollable area at zoomed size */ }
110- < div style = { { width : `${ zoom * 100 } %` , height : `${ zoom * 100 } %` } } />
111- { /* Iframe at full size, scaled via CSS transform */ }
92+ < div className = "flex-1 min-h-0 bg-[#0d0d1a]" >
11293 < iframe
113- src = { `/api/files/download?path=${ encodeURIComponent ( path ) } &inline=1` }
94+ key = { zoomPct }
95+ src = { pdfUrl }
11496 title = { path }
115- style = { {
116- position : "absolute" ,
117- top : 0 ,
118- left : 0 ,
119- width : `${ 100 / zoom } %` ,
120- height : `${ 100 / zoom } %` ,
121- border : "none" ,
122- transform : `scale(${ zoom } )` ,
123- transformOrigin : "top left" ,
124- } }
97+ className = "w-full h-full border-0"
12598 />
12699 </ div >
127100 </ div >
0 commit comments