import PageViewport from '~/interfaces/PageViewport'; /** * Zoom navigation controller for the PDF viewer. * * Manages all zoom-related interactions: the zoom dropdown menu, zoom in/out buttons, * direct percentage input, Ctrl+wheel zooming, and automatic re-zoom on window resize. * The controller emits zoom factor changes through a registered callback via {@link onChange}. */ export default class ZoomNav { /** Intrinsic page viewport size at the base scale, used for fit-to-page/width calculations. */ private readonly pageViewport; /** Toggle button/area that opens and closes the zoom dropdown menu. */ private readonly zoomToggle; /** The zoom dropdown menu element. */ private readonly zoomMenu; /** All selectable zoom preset buttons (percentage values and fit modes). */ private readonly zoomSelects; /** Button to decrease the zoom level by one step. */ private readonly zoomOutButton; /** Button to increase the zoom level by one step. */ private readonly zoomInButton; /** Form element wrapping the zoom input field. */ private readonly zoomForm; /** Input field displaying and accepting the current zoom percentage. */ private readonly zoomInput; /** The scrollable page view container, used for fit-to-page/width calculations. */ private readonly pageView; /** Timer ID for debouncing window resize events. */ private resizeTimeout; /** Last known zoom percentage value (e.g. 100 for 100%). Used as fallback for invalid input. */ private lastZoomFactor; /** Last selected zoom value string (e.g. "100", "pageWidth"). */ private lastZoomValue; /** Sorted list of numeric zoom percentages available in the dropdown (e.g. [50, 75, 100, ...]). */ private readonly zoomFactorList; /** Minimum zoom percentage available in the dropdown. */ private readonly minZoomFactor; /** Maximum zoom percentage available in the dropdown. */ private readonly maxZoomFactor; /** Callback invoked when the zoom factor changes. */ private changeListener; /** * Initializes the zoom navigation by querying dependent DOM nodes, * determining the initial zoom level, and binding all event listeners. * * If the PDF's intrinsic width exceeds the viewer container width, * the initial zoom is set to "fit to width"; otherwise it defaults to 100%. * * @param context - The root element containing all zoom-related elements. * @param pageViewport - The intrinsic page viewport size at the base scale. */ constructor(context: HTMLElement, pageViewport: PageViewport); /** * Opens the zoom dropdown menu. */ open(): void; /** * Closes the zoom dropdown menu. */ close(): void; /** * Returns the current zoom factor as a ratio (e.g. `1.5` for 150%). * * @returns The current zoom factor. */ getZoomFactor(): number; /** * Registers a callback that is invoked whenever the zoom factor changes. * * @param listener - Callback receiving the new zoom factor as a ratio. * @returns This instance for chaining. */ onChange(listener: (zoomFactor: number) => void): ZoomNav; /** * Positions the zoom dropdown menu below the toggle button using absolute coordinates. */ private layoutZoomMenuLayout; /** * Calculates the zoom factor for the given zoom value and updates the input display. * * @param strZoom - The zoom value (numeric percentage string or fit mode name). */ private updateInputZoom; /** * Removes the selection highlight from the currently selected zoom menu item. */ private deselectZoom; /** * Highlights the zoom menu item matching the given zoom value, if one exists. * * @param zoomValue - The zoom value to match against menu item `data-value` attributes. */ private activateZoom; /** * Parses the zoom percentage from the input field, clamps it to the valid range, * and applies the resulting zoom. If the input is not a valid number, * it is reverted to the last known valid zoom percentage. */ private enterZoom; /** * Steps the zoom level up or down to the nearest preset value in the dropdown list. * * @param zoomDir - Direction to zoom: {@link constants.ZOOM_OUT} or {@link constants.ZOOM_IN}. */ private calcNextZoom; /** * Returns the zoom menu button that is currently selected (highlighted), if any. * * @returns The selected zoom button element, or `undefined` if none is selected. */ private getSelectedZoomNode; /** * Returns the `data-value` of the currently selected zoom menu item. * * @returns The zoom value string (e.g. `"100"`, `"pageWidth"`), or `null` if none is selected. */ private getSelectedZoomValue; }