react-zoom-pan-pinch 3.6.0 → 3.7.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/dist/index.cjs.js CHANGED
@@ -528,7 +528,7 @@ function handlePanningStart(contextInstance, event) {
528
528
  handlePanningSetup(contextInstance, event);
529
529
  }
530
530
  }
531
- function handleAlignToBounds(contextInstance) {
531
+ function handleAlignToBounds(contextInstance, customAnimationTime) {
532
532
  var scale = contextInstance.transformState.scale;
533
533
  var _a = contextInstance.setup, minScale = _a.minScale, alignmentAnimation = _a.alignmentAnimation;
534
534
  var disabled = alignmentAnimation.disabled, sizeX = alignmentAnimation.sizeX, sizeY = alignmentAnimation.sizeY, animationTime = alignmentAnimation.animationTime, animationType = alignmentAnimation.animationType;
@@ -537,7 +537,7 @@ function handleAlignToBounds(contextInstance) {
537
537
  return;
538
538
  var targetState = handlePanToBounds(contextInstance);
539
539
  if (targetState) {
540
- animate(contextInstance, targetState, animationTime, animationType);
540
+ animate(contextInstance, targetState, customAnimationTime !== null && customAnimationTime !== void 0 ? customAnimationTime : animationTime, animationType);
541
541
  }
542
542
  }
543
543
  function handlePanning(contextInstance, clientX, clientY) {
@@ -648,7 +648,12 @@ function __spreadArray(to, from, pack) {
648
648
  }
649
649
  }
650
650
  return to.concat(ar || Array.prototype.slice.call(from));
651
- }
651
+ }
652
+
653
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
654
+ var e = new Error(message);
655
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
656
+ };
652
657
 
653
658
  var initialState = {
654
659
  previousScale: 1,
@@ -1435,32 +1440,43 @@ var ZoomPanPinch = /** @class */ (function () {
1435
1440
  wrapper.addEventListener("touchmove", _this.onTouchPanning, passive);
1436
1441
  wrapper.addEventListener("touchend", _this.onTouchPanningStop, passive);
1437
1442
  };
1438
- this.handleInitialize = function (contentComponent) {
1443
+ this.handleInitialize = function (wrapper, contentComponent) {
1444
+ var isCentered = false;
1439
1445
  var centerOnInit = _this.setup.centerOnInit;
1446
+ var hasTarget = function (entries, target) {
1447
+ // eslint-disable-next-line no-restricted-syntax
1448
+ for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
1449
+ var entry = entries_1[_i];
1450
+ if (entry.target === target) {
1451
+ return true;
1452
+ }
1453
+ }
1454
+ return false;
1455
+ };
1440
1456
  _this.applyTransformation();
1441
- _this.onInitCallbacks.forEach(function (callback) { return callback(getContext(_this)); });
1442
- if (centerOnInit) {
1443
- _this.setCenter();
1444
- _this.observer = new ResizeObserver(function () {
1445
- var _a;
1446
- var currentWidth = contentComponent.offsetWidth;
1447
- var currentHeight = contentComponent.offsetHeight;
1448
- if (currentWidth > 0 || currentHeight > 0) {
1449
- _this.onInitCallbacks.forEach(function (callback) {
1450
- return callback(getContext(_this));
1451
- });
1452
- _this.setCenter();
1453
- (_a = _this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
1457
+ _this.onInitCallbacks.forEach(function (callback) {
1458
+ callback(getContext(_this));
1459
+ });
1460
+ _this.observer = new ResizeObserver(function (entries) {
1461
+ if (hasTarget(entries, wrapper) || hasTarget(entries, contentComponent)) {
1462
+ if (centerOnInit && !isCentered) {
1463
+ var currentWidth = contentComponent.offsetWidth;
1464
+ var currentHeight = contentComponent.offsetHeight;
1465
+ if (currentWidth > 0 || currentHeight > 0) {
1466
+ isCentered = true;
1467
+ _this.setCenter();
1468
+ }
1454
1469
  }
1455
- });
1456
- // if nothing about the contentComponent has changed after 5 seconds, disconnect the observer
1457
- setTimeout(function () {
1458
- var _a;
1459
- (_a = _this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
1460
- }, 5000);
1461
- // Start observing the target node for configured mutations
1462
- _this.observer.observe(contentComponent);
1463
- }
1470
+ else {
1471
+ handleCancelAnimation(_this);
1472
+ handleCalculateBounds(_this, _this.transformState.scale);
1473
+ handleAlignToBounds(_this, 0);
1474
+ }
1475
+ }
1476
+ });
1477
+ // Start observing the target node for configured mutations
1478
+ _this.observer.observe(wrapper);
1479
+ _this.observer.observe(contentComponent);
1464
1480
  };
1465
1481
  /// ///////
1466
1482
  // Zoom
@@ -1602,11 +1618,10 @@ var ZoomPanPinch = /** @class */ (function () {
1602
1618
  var isAllowed = isPanningStartAllowed(_this, event);
1603
1619
  if (!isAllowed)
1604
1620
  return;
1605
- var isDoubleTap = _this.lastTouch && +new Date() - _this.lastTouch < 200;
1606
- if (isDoubleTap && event.touches.length === 1) {
1607
- _this.onDoubleClick(event);
1608
- }
1609
- else {
1621
+ var isDoubleTap = _this.lastTouch &&
1622
+ +new Date() - _this.lastTouch < 200 &&
1623
+ event.touches.length === 1;
1624
+ if (!isDoubleTap) {
1610
1625
  _this.lastTouch = +new Date();
1611
1626
  handleCancelAnimation(_this);
1612
1627
  var touches = event.touches;
@@ -1747,7 +1762,7 @@ var ZoomPanPinch = /** @class */ (function () {
1747
1762
  _this.contentComponent = contentComponent;
1748
1763
  handleCalculateBounds(_this, _this.transformState.scale);
1749
1764
  _this.handleInitializeWrapperEvents(wrapperComponent);
1750
- _this.handleInitialize(contentComponent);
1765
+ _this.handleInitialize(wrapperComponent, contentComponent);
1751
1766
  _this.initializeWindowEvents();
1752
1767
  _this.isInitialized = true;
1753
1768
  var ctx = getContext(_this);
@@ -1860,12 +1875,12 @@ var MiniMap = function (_a) {
1860
1875
  var rect = instance.wrapperComponent.getBoundingClientRect();
1861
1876
  return {
1862
1877
  width: rect.width,
1863
- height: rect.height
1878
+ height: rect.height,
1864
1879
  };
1865
1880
  }
1866
1881
  return {
1867
1882
  width: 0,
1868
- height: 0
1883
+ height: 0,
1869
1884
  };
1870
1885
  }, [instance.wrapperComponent]);
1871
1886
  var getContentSize = React.useCallback(function () {
@@ -1998,7 +2013,7 @@ function styleInject(css, ref) {
1998
2013
  }
1999
2014
  }
2000
2015
 
2001
- var css_248z = ".transform-component-module_wrapper__SPB86 {\n position: relative;\n width: -moz-fit-content;\n width: fit-content;\n height: -moz-fit-content;\n height: fit-content;\n overflow: hidden;\n -webkit-touch-callout: none; /* iOS Safari */\n -webkit-user-select: none; /* Safari */\n -khtml-user-select: none; /* Konqueror HTML */\n -moz-user-select: none; /* Firefox */\n -ms-user-select: none; /* Internet Explorer/Edge */\n user-select: none;\n margin: 0;\n padding: 0;\n}\n.transform-component-module_content__FBWxo {\n display: flex;\n flex-wrap: wrap;\n width: -moz-fit-content;\n width: fit-content;\n height: -moz-fit-content;\n height: fit-content;\n margin: 0;\n padding: 0;\n transform-origin: 0% 0%;\n}\n.transform-component-module_content__FBWxo img {\n pointer-events: none;\n}\n";
2016
+ var css_248z = ".transform-component-module_wrapper__SPB86 {\n position: relative;\n width: -moz-fit-content;\n width: fit-content;\n height: -moz-fit-content;\n height: fit-content;\n overflow: hidden;\n -webkit-touch-callout: none; /* iOS Safari */\n -webkit-user-select: none; /* Safari */\n -khtml-user-select: none; /* Konqueror HTML */\n -moz-user-select: none; /* Firefox */\n -ms-user-select: none; /* Internet Explorer/Edge */\n user-select: none;\n margin: 0;\n padding: 0;\n transform: translate3d(0, 0, 0);\n}\n.transform-component-module_content__FBWxo {\n display: flex;\n flex-wrap: wrap;\n width: -moz-fit-content;\n width: fit-content;\n height: -moz-fit-content;\n height: fit-content;\n margin: 0;\n padding: 0;\n transform-origin: 0% 0%;\n}\n.transform-component-module_content__FBWxo img {\n pointer-events: none;\n}\n";
2002
2017
  var styles = {"wrapper":"transform-component-module_wrapper__SPB86","content":"transform-component-module_content__FBWxo"};
2003
2018
  styleInject(css_248z);
2004
2019