From 4c1c3786efec2db95440f1e9e3ee60dc38aa9094 Mon Sep 17 00:00:00 2001 From: IgorA100 Date: Sat, 8 Jun 2024 23:55:22 +0300 Subject: [PATCH] Fix: If "opts.focal" - calculate coordinates taking into account the planned Scale, and not just the calculated Scale (panzoom.ts) --- src/panzoom.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/panzoom.ts b/src/panzoom.ts index 51722106..8b323a0e 100644 --- a/src/panzoom.ts +++ b/src/panzoom.ts @@ -314,6 +314,7 @@ function Panzoom( if (!opts.force && opts.disableZoom) { return } + const toScalePlanned = toScale toScale = result.scale let toX = x let toY = y @@ -323,8 +324,8 @@ function Panzoom( // plus the current translation after the scale // neutralized to no scale (as the transform scale will apply to the translation) const focal = opts.focal - toX = (focal.x / toScale - focal.x / scale + x * toScale) / toScale - toY = (focal.y / toScale - focal.y / scale + y * toScale) / toScale + toX = (focal.x / toScale - focal.x / scale + x * toScalePlanned) / toScalePlanned + toY = (focal.y / toScale - focal.y / scale + y * toScalePlanned) / toScalePlanned } const panResult = constrainXY(toX, toY, toScale, { relative: false, force: true }) x = panResult.x