Skip to content

Commit

Permalink
Implementing changes timmywil#512 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
patorpey committed Apr 13, 2021
1 parent ded6ef1 commit 8e15cf9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
3 changes: 2 additions & 1 deletion package.json
@@ -1,11 +1,12 @@
{
"name": "@panzoom/panzoom",
"version": "4.3.2",
"version": "4.3.3",
"description": "Pan and zoom elements anywhere using native transformations",
"main": "dist/panzoom.js",
"module": "dist/panzoom.es.js",
"source": "src/panzoom",
"types": "dist/src/panzoom.d.ts",
"private": true,
"scripts": {
"build": "npm run clean && rollup --config && npm run minify",
"clean": "rm -rf dist/",
Expand Down
43 changes: 24 additions & 19 deletions src/panzoom.ts
Expand Up @@ -7,24 +7,23 @@
* https://github.com/timmywil/panzoom/blob/master/MIT-License.txt
*
*/
import './polyfills'

import {getDimensions, setStyle, setTransform, setTransition} from './css';
import {destroyPointer, eventNames, onPointer} from './events';
import isAttached from './isAttached';
import isExcluded from './isExcluded';
import isSVGElement from './isSVGElement';
import {addPointer, getDistance, getMiddle, removePointer} from './pointers';
import shallowClone from './shallowClone';
import {
PanOptions,
PanzoomEvent,
PanzoomEventDetail,
PanzoomObject,
PanzoomOptions,
ZoomOptions
} from './types'
import { addPointer, getDistance, getMiddle, removePointer } from './pointers'
import { destroyPointer, eventNames, onPointer } from './events'
import { getDimensions, setStyle, setTransform, setTransition } from './css'
} from './types';

import isAttached from './isAttached'
import isExcluded from './isExcluded'
import isSVGElement from './isSVGElement'
import shallowClone from './shallowClone'

const defaultOptions: PanzoomOptions = {
animate: false,
Expand Down Expand Up @@ -468,21 +467,27 @@ function Panzoom(
addPointer(pointers, event)
const current = getMiddle(pointers)
if (pointers.length > 1) {
// #512 prevent zoom issue in mobile
if (startDistance === 0) {
startDistance = getDistance(pointers)
}
// Use the distance between the first 2 pointers
// to determine the current scale
const diff = getDistance(pointers) - startDistance
const toScale = constrainScale((diff * options.step) / 80 + startScale).scale
zoomToPoint(toScale, current)
}

pan(
origX + (current.clientX - startClientX) / scale,
origY + (current.clientY - startClientY) / scale,
{
animate: false
},
event
)
else {
// #512 added else condition to prevent mobile zoom focal point error
pan(
origX + (current.clientX - startClientX) / scale,
origY + (current.clientY - startClientY) / scale,
{
animate: false
},
event
)
}
}

function handleUp(event: PointerEvent) {
Expand Down Expand Up @@ -546,5 +551,5 @@ function Panzoom(

Panzoom.defaultOptions = defaultOptions

export { PanzoomObject, PanzoomOptions }
export {PanzoomObject, PanzoomOptions};
export default Panzoom
3 changes: 2 additions & 1 deletion tsconfig.json
@@ -1,5 +1,6 @@
{
"exclude": ["dist"],
"include": ["src"],
"compilerOptions": {
"alwaysStrict": true,
"esModuleInterop": true,
Expand All @@ -12,6 +13,6 @@
"sourceMap": true,
"strict": true,
"strictNullChecks": false,
"target": "es5"
"target": "es2018"
}
}

0 comments on commit 8e15cf9

Please sign in to comment.