react-zoom-pan-pinch 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.cjs.js +29 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +29 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/src/core/bounds/bounds.utils.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/transform-wrapper/transform-wrapper.tsx +3 -0
- package/src/core/bounds/bounds.utils.ts +43 -2
- package/src/stories/docs/props.tsx +1 -1
package/README.md
CHANGED
|
@@ -41,8 +41,8 @@ Do you like this library? Try out other projects
|
|
|
41
41
|
|
|
42
42
|
#### Sources
|
|
43
43
|
|
|
44
|
-
- [Demo](https://
|
|
45
|
-
- [Docs](https://
|
|
44
|
+
- [Demo](https://BetterTyped.github.io/react-zoom-pan-pinch/?path=/story/examples-big-image--big-image)
|
|
45
|
+
- [Docs](https://BetterTyped.github.io/react-zoom-pan-pinch/?path=/story/docs-props--page)
|
|
46
46
|
|
|
47
47
|
## Key Features
|
|
48
48
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -224,6 +224,28 @@ var calculateBounds = function (contextInstance, newScale) {
|
|
|
224
224
|
var bounds = getBounds(wrapperWidth, newContentWidth, newDiffWidth, wrapperHeight, newContentHeight, newDiffHeight, Boolean(centerZoomedOut));
|
|
225
225
|
return bounds;
|
|
226
226
|
};
|
|
227
|
+
function clamp(v, min, max) {
|
|
228
|
+
return Math.max(min, Math.min(v, max));
|
|
229
|
+
}
|
|
230
|
+
// Based on @aholachek ;)
|
|
231
|
+
// https://twitter.com/chpwn/status/285540192096497664
|
|
232
|
+
// iOS constant = 0.55
|
|
233
|
+
// https://medium.com/@nathangitter/building-fluid-interfaces-ios-swift-9732bb934bf5
|
|
234
|
+
function rubberband(distance, dimension, constant) {
|
|
235
|
+
if (dimension === 0 || Math.abs(dimension) === Infinity)
|
|
236
|
+
return Math.pow(distance, (constant * 5));
|
|
237
|
+
return (distance * dimension * constant) / (dimension + constant * distance);
|
|
238
|
+
}
|
|
239
|
+
function rubberbandIfOutOfBounds(position, min, max, constant) {
|
|
240
|
+
if (constant === void 0) { constant = 0.15; }
|
|
241
|
+
if (constant === 0)
|
|
242
|
+
return clamp(position, min, max);
|
|
243
|
+
if (position < min)
|
|
244
|
+
return -rubberband(min - position, max - min, constant) + min;
|
|
245
|
+
if (position > max)
|
|
246
|
+
return +rubberband(position - max, max - min, constant) + max;
|
|
247
|
+
return position;
|
|
248
|
+
}
|
|
227
249
|
/**
|
|
228
250
|
* Keeps value between given bounds, used for limiting view to given boundaries
|
|
229
251
|
* 1# eg. boundLimiter(2, 0, 3, true) => 2
|
|
@@ -254,8 +276,10 @@ function getMouseBoundedPosition(positionX, positionY, bounds, limitToBounds, pa
|
|
|
254
276
|
paddingX = paddingValueX;
|
|
255
277
|
paddingY = paddingValueY;
|
|
256
278
|
}
|
|
257
|
-
var
|
|
258
|
-
var
|
|
279
|
+
var rubberbandX = rubberbandIfOutOfBounds(positionX, minPositionX, maxPositionX);
|
|
280
|
+
var rubberbandY = rubberbandIfOutOfBounds(positionY, minPositionY, maxPositionY);
|
|
281
|
+
var x = boundLimiter(rubberbandX, minPositionX - paddingX, maxPositionX + paddingX, limitToBounds);
|
|
282
|
+
var y = boundLimiter(rubberbandY, minPositionY - paddingY, maxPositionY + paddingY, limitToBounds);
|
|
259
283
|
return { x: x, y: y };
|
|
260
284
|
}
|
|
261
285
|
|
|
@@ -1682,6 +1706,9 @@ var TransformWrapper = React__default["default"].forwardRef(function (props, ref
|
|
|
1682
1706
|
React.useImperativeHandle(ref, function () { return getControls(instance); }, [instance]);
|
|
1683
1707
|
React.useEffect(function () {
|
|
1684
1708
|
instance.update(props);
|
|
1709
|
+
return function () {
|
|
1710
|
+
instance.cleanupWindowEvents();
|
|
1711
|
+
};
|
|
1685
1712
|
}, [instance, props]);
|
|
1686
1713
|
return React__default["default"].createElement(Context.Provider, { value: instance }, content);
|
|
1687
1714
|
});
|