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 CHANGED
@@ -41,8 +41,8 @@ Do you like this library? Try out other projects
41
41
 
42
42
  #### Sources
43
43
 
44
- - [Demo](https://prc5.github.io/react-zoom-pan-pinch/?path=/story/examples-big-image--big-image)
45
- - [Docs](https://prc5.github.io/react-zoom-pan-pinch/?path=/story/docs-props--page)
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 x = boundLimiter(positionX, minPositionX - paddingX, maxPositionX + paddingX, limitToBounds);
258
- var y = boundLimiter(positionY, minPositionY - paddingY, maxPositionY + paddingY, limitToBounds);
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
  });