Cleanup panzoom implementation

This commit is contained in:
ZXY101
2023-08-01 13:47:06 +02:00
parent e4756e87a4
commit 3c2199b06a
4 changed files with 35 additions and 25 deletions

23
src/lib/panzoom/util.ts Normal file
View File

@@ -0,0 +1,23 @@
import panzoom from 'panzoom';
import type { PanZoom } from 'panzoom';
import { writable } from 'svelte/store';
export const pz = writable<PanZoom | undefined>(undefined);
export function initPanzoom(node: HTMLElement) {
pz.set(
panzoom(node, {
bounds: false,
maxZoom: 10,
minZoom: 0.1,
zoomDoubleClickSpeed: 1,
enableTextSelection: true,
beforeMouseDown: (e) => {
const nodeName = (e.target as HTMLElement).nodeName;
return nodeName === 'P';
},
beforeWheel: (e) => e.altKey,
onTouch: (e) => e.touches.length > 1
})
);
}