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/dist/index.esm.js
CHANGED
|
@@ -216,6 +216,28 @@ var calculateBounds = function (contextInstance, newScale) {
|
|
|
216
216
|
var bounds = getBounds(wrapperWidth, newContentWidth, newDiffWidth, wrapperHeight, newContentHeight, newDiffHeight, Boolean(centerZoomedOut));
|
|
217
217
|
return bounds;
|
|
218
218
|
};
|
|
219
|
+
function clamp(v, min, max) {
|
|
220
|
+
return Math.max(min, Math.min(v, max));
|
|
221
|
+
}
|
|
222
|
+
// Based on @aholachek ;)
|
|
223
|
+
// https://twitter.com/chpwn/status/285540192096497664
|
|
224
|
+
// iOS constant = 0.55
|
|
225
|
+
// https://medium.com/@nathangitter/building-fluid-interfaces-ios-swift-9732bb934bf5
|
|
226
|
+
function rubberband(distance, dimension, constant) {
|
|
227
|
+
if (dimension === 0 || Math.abs(dimension) === Infinity)
|
|
228
|
+
return Math.pow(distance, (constant * 5));
|
|
229
|
+
return (distance * dimension * constant) / (dimension + constant * distance);
|
|
230
|
+
}
|
|
231
|
+
function rubberbandIfOutOfBounds(position, min, max, constant) {
|
|
232
|
+
if (constant === void 0) { constant = 0.15; }
|
|
233
|
+
if (constant === 0)
|
|
234
|
+
return clamp(position, min, max);
|
|
235
|
+
if (position < min)
|
|
236
|
+
return -rubberband(min - position, max - min, constant) + min;
|
|
237
|
+
if (position > max)
|
|
238
|
+
return +rubberband(position - max, max - min, constant) + max;
|
|
239
|
+
return position;
|
|
240
|
+
}
|
|
219
241
|
/**
|
|
220
242
|
* Keeps value between given bounds, used for limiting view to given boundaries
|
|
221
243
|
* 1# eg. boundLimiter(2, 0, 3, true) => 2
|
|
@@ -246,8 +268,10 @@ function getMouseBoundedPosition(positionX, positionY, bounds, limitToBounds, pa
|
|
|
246
268
|
paddingX = paddingValueX;
|
|
247
269
|
paddingY = paddingValueY;
|
|
248
270
|
}
|
|
249
|
-
var
|
|
250
|
-
var
|
|
271
|
+
var rubberbandX = rubberbandIfOutOfBounds(positionX, minPositionX, maxPositionX);
|
|
272
|
+
var rubberbandY = rubberbandIfOutOfBounds(positionY, minPositionY, maxPositionY);
|
|
273
|
+
var x = boundLimiter(rubberbandX, minPositionX - paddingX, maxPositionX + paddingX, limitToBounds);
|
|
274
|
+
var y = boundLimiter(rubberbandY, minPositionY - paddingY, maxPositionY + paddingY, limitToBounds);
|
|
251
275
|
return { x: x, y: y };
|
|
252
276
|
}
|
|
253
277
|
|
|
@@ -1674,6 +1698,9 @@ var TransformWrapper = React.forwardRef(function (props, ref) {
|
|
|
1674
1698
|
useImperativeHandle(ref, function () { return getControls(instance); }, [instance]);
|
|
1675
1699
|
useEffect(function () {
|
|
1676
1700
|
instance.update(props);
|
|
1701
|
+
return function () {
|
|
1702
|
+
instance.cleanupWindowEvents();
|
|
1703
|
+
};
|
|
1677
1704
|
}, [instance, props]);
|
|
1678
1705
|
return React.createElement(Context.Provider, { value: instance }, content);
|
|
1679
1706
|
});
|