2025-09-15 18:20:11 +01:00
|
|
|
import { useEffect, useRef } from 'react';
|
2025-09-11 19:08:44 +01:00
|
|
|
import { useZoom } from '@embedpdf/plugin-zoom/react';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component that runs inside EmbedPDF context and exports zoom controls globally
|
|
|
|
*/
|
2025-09-12 16:26:05 +01:00
|
|
|
export function ZoomAPIBridge() {
|
2025-09-11 19:08:44 +01:00
|
|
|
const { provides: zoom, state: zoomState } = useZoom();
|
2025-09-15 18:20:11 +01:00
|
|
|
const hasSetInitialZoom = useRef(false);
|
|
|
|
|
|
|
|
// Set initial zoom once when plugin is ready
|
|
|
|
useEffect(() => {
|
|
|
|
if (zoom && !hasSetInitialZoom.current) {
|
|
|
|
hasSetInitialZoom.current = true;
|
|
|
|
setTimeout(() => {
|
|
|
|
console.log('Setting initial zoom to 140%');
|
|
|
|
zoom.requestZoom(1.4);
|
|
|
|
}, 50);
|
|
|
|
}
|
|
|
|
}, [zoom]);
|
2025-09-11 19:08:44 +01:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (zoom) {
|
2025-09-15 18:20:11 +01:00
|
|
|
|
2025-09-11 19:08:44 +01:00
|
|
|
// Export zoom controls to global window for right rail access
|
|
|
|
(window as any).embedPdfZoom = {
|
|
|
|
zoomIn: () => zoom.zoomIn(),
|
|
|
|
zoomOut: () => zoom.zoomOut(),
|
|
|
|
toggleMarqueeZoom: () => zoom.toggleMarqueeZoom(),
|
|
|
|
requestZoom: (level: any) => zoom.requestZoom(level),
|
2025-09-15 18:20:11 +01:00
|
|
|
currentZoom: zoomState?.currentZoomLevel || 1.4,
|
|
|
|
zoomPercent: Math.round((zoomState?.currentZoomLevel || 1.4) * 100),
|
2025-09-11 19:08:44 +01:00
|
|
|
};
|
2025-09-12 16:26:05 +01:00
|
|
|
|
2025-09-11 19:08:44 +01:00
|
|
|
}
|
|
|
|
}, [zoom, zoomState]);
|
|
|
|
|
2025-09-12 16:26:05 +01:00
|
|
|
return null;
|
|
|
|
}
|