File size: 1,488 Bytes
ed9f15f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
/**
* Zoom Controls - Image zoom functionality
*/
import { getZoomLevel, setZoomLevel } from '../state.js';
import { ZOOM_CONFIG } from '../config.js';
/**
* Adjust zoom level
*/
export function adjustZoom(delta) {
const currentZoom = getZoomLevel();
const newZoom = Math.max(ZOOM_CONFIG.min, Math.min(ZOOM_CONFIG.max, currentZoom + delta));
setZoomLevel(newZoom);
applyZoom();
}
/**
* Reset zoom to default
*/
export function resetZoom() {
setZoomLevel(ZOOM_CONFIG.default);
applyZoom();
}
/**
* Apply current zoom level to image
*/
function applyZoom() {
const img = document.getElementById('mainImage');
const zoomLevel = getZoomLevel();
if (img) {
img.style.transform = `scale(${zoomLevel})`;
}
const zoomDisplay = document.getElementById('zoomLevel');
if (zoomDisplay) {
zoomDisplay.textContent = `Zoom: ${Math.round(zoomLevel * 100)}%`;
}
}
/**
* Setup zoom event listeners
*/
export function setupZoomListeners() {
const zoomIn = document.getElementById('zoomIn');
const zoomOut = document.getElementById('zoomOut');
const zoomReset = document.getElementById('zoomReset');
if (zoomIn) zoomIn.addEventListener('click', () => adjustZoom(ZOOM_CONFIG.step));
if (zoomOut) zoomOut.addEventListener('click', () => adjustZoom(-ZOOM_CONFIG.step));
if (zoomReset) zoomReset.addEventListener('click', resetZoom);
}
|