From 510d567dc893f35757989cbccb8a42b678db9916 Mon Sep 17 00:00:00 2001 From: Quentin Savoye Date: Thu, 4 Dec 2025 17:01:51 +0100 Subject: [PATCH] fix panning not working on additionnal window --- src/core/pan/panning.logic.ts | 3 ++- src/core/pan/panning.utils.ts | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/core/pan/panning.logic.ts b/src/core/pan/panning.logic.ts index 9c560f99..d6723953 100644 --- a/src/core/pan/panning.logic.ts +++ b/src/core/pan/panning.logic.ts @@ -69,7 +69,8 @@ export function handlePanning( const paddingValueX = getPaddingValue(contextInstance, sizeX); const paddingValueY = getPaddingValue(contextInstance, sizeY); - if(clientCoords?.x != clientX && clientCoords?.y != clientY) handleCalculateVelocity(contextInstance, { x, y }); + if (clientCoords?.x != clientX && clientCoords?.y != clientY) + handleCalculateVelocity(contextInstance, { x, y }); handleNewPosition(contextInstance, x, y, paddingValueX, paddingValueY); } diff --git a/src/core/pan/panning.utils.ts b/src/core/pan/panning.utils.ts index d4871369..de3136d4 100644 --- a/src/core/pan/panning.utils.ts +++ b/src/core/pan/panning.utils.ts @@ -17,9 +17,18 @@ export const isPanningStartAllowed = ( const target = event.target as HTMLElement; const targetIsShadowDom = "shadowRoot" in target && "composedPath" in event; + + // Helper function to check if an object is an Element (cross-window compatible) + // Using numeric constant 1 (ELEMENT_NODE) instead of Node.ELEMENT_NODE for cross-window compatibility + const isElement = (el: unknown): el is Element => { + return ( + el != null && typeof el === "object" && (el as Element).nodeType === 1 + ); + }; + const isWrapperChild = targetIsShadowDom ? event.composedPath().some((el) => { - if (!(el instanceof Element)) { + if (!isElement(el)) { return false; } @@ -64,7 +73,7 @@ export const handlePanningSetup = ( const y = event.clientY; contextInstance.startCoords = { x: x - positionX, y: y - positionY }; - contextInstance.clientCoords = {x: x, y: y}; + contextInstance.clientCoords = { x, y }; }; export const handleTouchPanningSetup = ( @@ -82,7 +91,7 @@ export const handleTouchPanningSetup = ( const x = touches[0].clientX; const y = touches[0].clientY; contextInstance.startCoords = { x: x - positionX, y: y - positionY }; - contextInstance.clientCoords = {x: x, y: y}; + contextInstance.clientCoords = { x, y }; } }; export function handlePanToBounds(