blob: 86f672733e69ba785f5aef4ca338b68d4d49bd4b (
plain)
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
|
import { pan, zoom } from 'pan-zoom';
const storageKey = 'pan-zoom',
zoomFactor = 0.25;
function restorePanZoomVal(svg) {
const storedPanZoomVal = localStorage.getItem(storageKey);
if (storedPanZoomVal) {
svg.style.transform = storedPanZoomVal;
}
}
function addEventListeners(svg) {
svg.addEventListener('wheel', e => zoom(svg, e, zoomFactor), { passive: false });
svg.addEventListener('pointerdown', e => pan(svg, e), { passive: false });
}
function storePanZoomVal(transformMatrix) {
localStorage.setItem(storageKey, transformMatrix);
}
function observePanZoomChanges(svg) {
const observer = new MutationObserver(() => storePanZoomVal(svg.style.transform));
observer.observe(svg, { attributeFilter: ['style'] });
}
export function start(svg) {
restorePanZoomVal(svg);
addEventListeners(svg);
observePanZoomChanges(svg);
}
|