diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index c1639d60..c779d564 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,4 +1,4 @@ -import { enableScroll, disableScroll } from "./scroll" +import { enableScroll, disableScroll, clamp } from "./utils" export type ZoomImageOptions = { customZoom?: { width: number; height: number } @@ -18,10 +18,6 @@ type ZoomImageStore = { zoomLens: HTMLDivElement } -function clamp(value: number, min: number, max: number) { - return Math.max(min, Math.min(max, value)) -} - function createZoomImage(container: HTMLElement, options: ZoomImageOptions = {}) { if (!container) { throw new Error("Please specify a container for the zoom image") diff --git a/packages/core/src/scroll.ts b/packages/core/src/utils.ts similarity index 73% rename from packages/core/src/scroll.ts rename to packages/core/src/utils.ts index 2e7862b0..46b9e288 100644 --- a/packages/core/src/scroll.ts +++ b/packages/core/src/utils.ts @@ -1,9 +1,12 @@ -const keySet = new Set(["ArrowUp", "ArrowRight", "ArrowDown", "ArrowLeft"]) +export function clamp(value: number, min: number, max: number) { + return Math.max(min, Math.min(max, value)) +} function preventDefault(event: Event) { event.preventDefault() } +const keySet = new Set(["ArrowUp", "ArrowRight", "ArrowDown", "ArrowLeft"]) function preventDefaultForScrollKeys(event: KeyboardEvent) { if (keySet.has(event.key)) { preventDefault(event) @@ -11,12 +14,10 @@ function preventDefaultForScrollKeys(event: KeyboardEvent) { } } -const wheelOpt = { passive: false } - export function disableScroll() { window.addEventListener("DOMMouseScroll", preventDefault) - window.addEventListener("wheel", preventDefault, wheelOpt) - window.addEventListener("touchmove", preventDefault, wheelOpt) + window.addEventListener("wheel", preventDefault, { passive: false }) + window.addEventListener("touchmove", preventDefault, { passive: false }) window.addEventListener("keydown", preventDefaultForScrollKeys) }