react-zoom-pan-pinch 1.5.5 → 1.6.1
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 +8 -8
- package/dist/components/TransformWrapper.d.ts +2 -2
- package/dist/index.es.js +106 -69
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +106 -69
- package/dist/index.js.map +1 -1
- package/dist/store/InitialState.d.ts +2 -2
- package/dist/store/StateContext.d.ts +2 -2
- package/dist/store/interfaces/propsInterface.d.ts +84 -69
- package/dist/store/interfaces/transformWrapperInterface.d.ts +21 -0
- package/dist/store/utils.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -76,6 +76,7 @@ var initialState = {
|
|
|
76
76
|
minScale: 1,
|
|
77
77
|
maxScale: 8,
|
|
78
78
|
limitToBounds: true,
|
|
79
|
+
limitToWrapper: false,
|
|
79
80
|
centerContent: true,
|
|
80
81
|
wrapperClass: "",
|
|
81
82
|
contentClass: "",
|
|
@@ -85,7 +86,7 @@ var initialState = {
|
|
|
85
86
|
step: 5,
|
|
86
87
|
wheelEnabled: true,
|
|
87
88
|
touchPadEnabled: true,
|
|
88
|
-
|
|
89
|
+
limitsOnWheel: false,
|
|
89
90
|
},
|
|
90
91
|
pan: {
|
|
91
92
|
disabled: false,
|
|
@@ -94,15 +95,14 @@ var initialState = {
|
|
|
94
95
|
lockAxisY: false,
|
|
95
96
|
velocity: true,
|
|
96
97
|
velocityEqualToMove: true,
|
|
97
|
-
velocitySensitivity:
|
|
98
|
+
velocitySensitivity: 2,
|
|
98
99
|
velocityActiveScale: 1,
|
|
99
|
-
velocityMinSpeed:
|
|
100
|
+
velocityMinSpeed: 1,
|
|
100
101
|
velocityBaseTime: 1600,
|
|
101
|
-
velocityAnimationType: "
|
|
102
|
-
limitToWrapperBounds: false,
|
|
102
|
+
velocityAnimationType: "easeOutQuart",
|
|
103
103
|
padding: true,
|
|
104
104
|
paddingSize: 30,
|
|
105
|
-
panReturnAnimationTime:
|
|
105
|
+
panReturnAnimationTime: 400,
|
|
106
106
|
panReturnAnimationType: "easeOut",
|
|
107
107
|
disableOnTarget: [],
|
|
108
108
|
},
|
|
@@ -179,12 +179,12 @@ var boundLimiter = function (value, minBound, maxBound, isActive) {
|
|
|
179
179
|
/**
|
|
180
180
|
* Calculate bounding area of zoomed/panned element
|
|
181
181
|
*/
|
|
182
|
-
var calculateBoundingArea = function (wrapperWidth, newContentWidth, diffWidth, wrapperHeight, newContentHeight, diffHeight,
|
|
182
|
+
var calculateBoundingArea = function (wrapperWidth, newContentWidth, diffWidth, wrapperHeight, newContentHeight, diffHeight, limitToWrapper) {
|
|
183
183
|
var scaleWidthFactor = wrapperWidth > newContentWidth
|
|
184
|
-
? diffWidth * (
|
|
184
|
+
? diffWidth * (limitToWrapper ? 1 : 0.5)
|
|
185
185
|
: 0;
|
|
186
186
|
var scaleHeightFactor = wrapperHeight > newContentHeight
|
|
187
|
-
? diffHeight * (
|
|
187
|
+
? diffHeight * (limitToWrapper ? 1 : 0.5)
|
|
188
188
|
: 0;
|
|
189
189
|
var minPositionX = wrapperWidth - newContentWidth - scaleWidthFactor;
|
|
190
190
|
var maxPositionX = scaleWidthFactor;
|
|
@@ -516,7 +516,7 @@ function handlePanningAnimation() {
|
|
|
516
516
|
});
|
|
517
517
|
}
|
|
518
518
|
function handlePanToBounds() {
|
|
519
|
-
var _a = this.stateProvider, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale, _b = _a.options, disabled = _b.disabled, limitToBounds = _b.limitToBounds;
|
|
519
|
+
var _a = this.stateProvider, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale, _b = _a.options, disabled = _b.disabled, limitToBounds = _b.limitToBounds, limitToWrapper = _b.limitToWrapper;
|
|
520
520
|
var wrapperComponent = this.state.wrapperComponent;
|
|
521
521
|
if (disabled)
|
|
522
522
|
return;
|
|
@@ -531,7 +531,7 @@ function handlePanToBounds() {
|
|
|
531
531
|
: this.stateProvider.minPositionY || 0;
|
|
532
532
|
var mousePosX = mouseX;
|
|
533
533
|
var mousePosY = mouseY;
|
|
534
|
-
var _d = handleCalculatePositions.call(this, mousePosX, mousePosY, scale, this.bounds, limitToBounds), x = _d.x, y = _d.y;
|
|
534
|
+
var _d = handleCalculatePositions.call(this, mousePosX, mousePosY, scale, this.bounds, limitToBounds || limitToWrapper), x = _d.x, y = _d.y;
|
|
535
535
|
return {
|
|
536
536
|
scale: scale,
|
|
537
537
|
positionX: xChanged ? x : positionX,
|
|
@@ -581,7 +581,7 @@ function handleCalculateBounds(newScale, limitToWrapper) {
|
|
|
581
581
|
* Wheel zoom event
|
|
582
582
|
*/
|
|
583
583
|
function handleWheelZoom(event) {
|
|
584
|
-
var _a = this.stateProvider, scale = _a.scale, contentComponent = _a.contentComponent, limitToBounds = _a.options.limitToBounds, _b = _a.scalePadding, size = _b.size, disabled = _b.disabled, _c = _a.wheel, step = _c.step,
|
|
584
|
+
var _a = this.stateProvider, scale = _a.scale, contentComponent = _a.contentComponent, limitToBounds = _a.options.limitToBounds, _b = _a.scalePadding, size = _b.size, disabled = _b.disabled, _c = _a.wheel, step = _c.step, limitsOnWheel = _c.limitsOnWheel;
|
|
585
585
|
event.preventDefault();
|
|
586
586
|
event.stopPropagation();
|
|
587
587
|
var delta = getDelta(event, null);
|
|
@@ -589,9 +589,9 @@ function handleWheelZoom(event) {
|
|
|
589
589
|
// if scale not change
|
|
590
590
|
if (scale === newScale)
|
|
591
591
|
return;
|
|
592
|
-
var bounds = handleCalculateBounds.call(this, newScale,
|
|
592
|
+
var bounds = handleCalculateBounds.call(this, newScale, !limitsOnWheel);
|
|
593
593
|
var _d = wheelMousePosition(event, contentComponent, scale), mouseX = _d.mouseX, mouseY = _d.mouseY;
|
|
594
|
-
var isLimitedToBounds = limitToBounds && (disabled || size === 0 ||
|
|
594
|
+
var isLimitedToBounds = limitToBounds && (disabled || size === 0 || limitsOnWheel);
|
|
595
595
|
var _e = handleCalculatePositions.call(this, mouseX, mouseY, newScale, bounds, isLimitedToBounds), x = _e.x, y = _e.y;
|
|
596
596
|
this.bounds = bounds;
|
|
597
597
|
this.stateProvider.previousScale = scale;
|
|
@@ -604,11 +604,11 @@ function handleWheelZoom(event) {
|
|
|
604
604
|
* Zoom for animations
|
|
605
605
|
*/
|
|
606
606
|
function handleZoomToPoint(isDisabled, scale, mouseX, mouseY, event) {
|
|
607
|
-
var _a = this.stateProvider, contentComponent = _a.contentComponent, _b = _a.options, disabled = _b.disabled, minScale = _b.minScale, maxScale = _b.maxScale, limitToBounds = _b.limitToBounds;
|
|
607
|
+
var _a = this.stateProvider, contentComponent = _a.contentComponent, _b = _a.options, disabled = _b.disabled, minScale = _b.minScale, maxScale = _b.maxScale, limitToBounds = _b.limitToBounds, limitToWrapper = _b.limitToWrapper;
|
|
608
608
|
if (disabled || isDisabled)
|
|
609
609
|
return;
|
|
610
610
|
var newScale = checkZoomBounds(roundNumber(scale, 2), minScale, maxScale, null, null);
|
|
611
|
-
var bounds = handleCalculateBounds.call(this, newScale,
|
|
611
|
+
var bounds = handleCalculateBounds.call(this, newScale, limitToWrapper);
|
|
612
612
|
var mousePosX = mouseX;
|
|
613
613
|
var mousePosY = mouseY;
|
|
614
614
|
// if event is present - use it's mouse position
|
|
@@ -621,9 +621,9 @@ function handleZoomToPoint(isDisabled, scale, mouseX, mouseY, event) {
|
|
|
621
621
|
return { scale: newScale, positionX: x, positionY: y };
|
|
622
622
|
}
|
|
623
623
|
function handlePaddingAnimation$1() {
|
|
624
|
-
var _a = this.stateProvider, scale = _a.scale, wrapperComponent = _a.wrapperComponent,
|
|
624
|
+
var _a = this.stateProvider, scale = _a.scale, wrapperComponent = _a.wrapperComponent, _b = _a.options, minScale = _b.minScale, limitToBounds = _b.limitToBounds, _c = _a.scalePadding, disabled = _c.disabled, animationTime = _c.animationTime, animationType = _c.animationType;
|
|
625
625
|
var isDisabled = disabled || scale >= minScale;
|
|
626
|
-
if (scale >= 1) {
|
|
626
|
+
if (scale >= 1 || limitToBounds) {
|
|
627
627
|
// fire fit to bounds animation
|
|
628
628
|
handlePanningAnimation.call(this);
|
|
629
629
|
}
|
|
@@ -666,8 +666,8 @@ function handleZoomControls(customDelta, customStep) {
|
|
|
666
666
|
var _a = this.stateProvider, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY, wrapperComponent = _a.wrapperComponent, zoomIn = _a.zoomIn, zoomOut = _a.zoomOut;
|
|
667
667
|
var wrapperWidth = wrapperComponent.offsetWidth;
|
|
668
668
|
var wrapperHeight = wrapperComponent.offsetHeight;
|
|
669
|
-
var mouseX = (
|
|
670
|
-
var mouseY = (
|
|
669
|
+
var mouseX = (wrapperWidth / 2 - positionX) / scale;
|
|
670
|
+
var mouseY = (wrapperHeight / 2 - positionY) / scale;
|
|
671
671
|
var newScale = handleCalculateZoom.call(this, customDelta, customStep, undefined, undefined, true);
|
|
672
672
|
var isZoomIn = newScale > scale;
|
|
673
673
|
var animationSpeed = isZoomIn
|
|
@@ -688,7 +688,7 @@ function handleZoomControls(customDelta, customStep) {
|
|
|
688
688
|
}
|
|
689
689
|
function resetTransformations(animationSpeed) {
|
|
690
690
|
var _a = this.props.defaultValues, defaultScale = _a.defaultScale, defaultPositionX = _a.defaultPositionX, defaultPositionY = _a.defaultPositionY;
|
|
691
|
-
var _b = this.stateProvider, scale = _b.scale, positionX = _b.positionX, positionY = _b.positionY,
|
|
691
|
+
var _b = this.stateProvider, scale = _b.scale, positionX = _b.positionX, positionY = _b.positionY, reset = _b.reset, _c = _b.options, disabled = _c.disabled, limitToBounds = _c.limitToBounds, centerContent = _c.centerContent, limitToWrapper = _c.limitToWrapper;
|
|
692
692
|
if (disabled || reset.disabled)
|
|
693
693
|
return;
|
|
694
694
|
if (scale === defaultScale &&
|
|
@@ -699,6 +699,11 @@ function resetTransformations(animationSpeed) {
|
|
|
699
699
|
var targetScale = checkIsNumber(defaultScale, initialState.scale);
|
|
700
700
|
var newPositionX = checkIsNumber(defaultPositionX, initialState.positionX);
|
|
701
701
|
var newPositionY = checkIsNumber(defaultPositionY, initialState.positionY);
|
|
702
|
+
if ((limitToBounds && !limitToWrapper) || centerContent) {
|
|
703
|
+
var bounds = handleCalculateBounds.call(this, targetScale, limitToWrapper);
|
|
704
|
+
newPositionX = bounds.minPositionX;
|
|
705
|
+
newPositionY = bounds.minPositionY;
|
|
706
|
+
}
|
|
702
707
|
var targetState = {
|
|
703
708
|
scale: targetScale,
|
|
704
709
|
positionX: newPositionX,
|
|
@@ -748,7 +753,7 @@ function calculateMidpoint(event, scale, contentComponent) {
|
|
|
748
753
|
};
|
|
749
754
|
}
|
|
750
755
|
function handleZoomPinch(event) {
|
|
751
|
-
var _a = this.stateProvider, scale = _a.scale,
|
|
756
|
+
var _a = this.stateProvider, scale = _a.scale, _b = _a.options, limitToBounds = _b.limitToBounds, limitToWrapper = _b.limitToWrapper, _c = _a.scalePadding, disabled = _c.disabled, size = _c.size, limitsOnWheel = _a.wheel.limitsOnWheel, pinch = _a.pinch;
|
|
752
757
|
var contentComponent = this.state.contentComponent;
|
|
753
758
|
if (pinch.disabled || this.stateProvider.options.disabled)
|
|
754
759
|
return;
|
|
@@ -760,7 +765,7 @@ function handleZoomPinch(event) {
|
|
|
760
765
|
if (this.pinchStartDistance === null)
|
|
761
766
|
return;
|
|
762
767
|
// Position transformation
|
|
763
|
-
var
|
|
768
|
+
var _d = calculateMidpoint(event, scale, contentComponent), mouseX = _d.mouseX, mouseY = _d.mouseY;
|
|
764
769
|
// if touches goes off of the wrapper element
|
|
765
770
|
if (checkIfInfinite(mouseX) || checkIfInfinite(mouseY))
|
|
766
771
|
return;
|
|
@@ -769,10 +774,10 @@ function handleZoomPinch(event) {
|
|
|
769
774
|
if (checkIfInfinite(newScale) || newScale === scale)
|
|
770
775
|
return;
|
|
771
776
|
// Get new element sizes to calculate bounds
|
|
772
|
-
var bounds = handleCalculateBounds.call(this, newScale);
|
|
777
|
+
var bounds = handleCalculateBounds.call(this, newScale, limitToWrapper);
|
|
773
778
|
// Calculate transformations
|
|
774
|
-
var isLimitedToBounds = limitToBounds && (disabled || size === 0 ||
|
|
775
|
-
var
|
|
779
|
+
var isLimitedToBounds = limitToBounds && (disabled || size === 0 || limitsOnWheel);
|
|
780
|
+
var _e = handleCalculatePositions.call(this, mouseX, mouseY, newScale, bounds, isLimitedToBounds), x = _e.x, y = _e.y;
|
|
776
781
|
this.lastDistance = currentDistance;
|
|
777
782
|
this.stateProvider.positionX = x;
|
|
778
783
|
this.stateProvider.positionY = y;
|
|
@@ -798,7 +803,7 @@ function handleFireVelocity() {
|
|
|
798
803
|
}
|
|
799
804
|
function animateVelocity() {
|
|
800
805
|
var _this = this;
|
|
801
|
-
var _a = this.stateProvider, positionX = _a.positionX, positionY = _a.positionY, limitToBounds = _a.options.limitToBounds, _b = _a.pan, velocityBaseTime = _b.velocityBaseTime, lockAxisX = _b.lockAxisX, lockAxisY = _b.lockAxisY, velocityAnimationType = _b.velocityAnimationType, panReturnAnimationTime = _b.panReturnAnimationTime, padding = _b.padding, paddingSize = _b.paddingSize, wrapperComponent = _a.wrapperComponent;
|
|
806
|
+
var _a = this.stateProvider, positionX = _a.positionX, positionY = _a.positionY, limitToBounds = _a.options.limitToBounds, _b = _a.pan, velocityBaseTime = _b.velocityBaseTime, lockAxisX = _b.lockAxisX, lockAxisY = _b.lockAxisY, velocityAnimationType = _b.velocityAnimationType, panReturnAnimationTime = _b.panReturnAnimationTime, panReturnAnimationType = _b.panReturnAnimationType, padding = _b.padding, paddingSize = _b.paddingSize, wrapperComponent = _a.wrapperComponent;
|
|
802
807
|
if (!this.mounted)
|
|
803
808
|
return;
|
|
804
809
|
if (!this.velocity || !this.bounds)
|
|
@@ -812,35 +817,40 @@ function animateVelocity() {
|
|
|
812
817
|
}
|
|
813
818
|
var targetX = velocityX;
|
|
814
819
|
var targetY = velocityY;
|
|
815
|
-
this.offsetX = positionX;
|
|
816
|
-
this.offsetY = positionY;
|
|
817
820
|
// pan return animation
|
|
818
821
|
var newAnimationTime = animationTime > panReturnAnimationTime
|
|
819
822
|
? animationTime
|
|
820
823
|
: panReturnAnimationTime;
|
|
821
|
-
var isReturnAnimationLonger = animationTime < panReturnAnimationTime;
|
|
822
|
-
var maxTargetX = positionX - maxPositionX;
|
|
823
|
-
var minTargetX = positionX - minPositionX;
|
|
824
|
-
var maxTargetY = positionY - maxPositionY;
|
|
825
|
-
var minTargetY = positionY - minPositionY;
|
|
826
824
|
var paddingValue = padding ? paddingSize : 0;
|
|
825
|
+
var paddingX = wrapperComponent
|
|
826
|
+
? (paddingValue * wrapperComponent.offsetWidth) / 100
|
|
827
|
+
: 0;
|
|
828
|
+
var paddingY = wrapperComponent
|
|
829
|
+
? (paddingValue * wrapperComponent.offsetHeight) / 100
|
|
830
|
+
: 0;
|
|
831
|
+
var maxTargetX = maxPositionX + paddingX;
|
|
832
|
+
var minTargetX = minPositionX - paddingX;
|
|
833
|
+
var maxTargetY = maxPositionY + paddingY;
|
|
834
|
+
var minTargetY = minPositionY - paddingY;
|
|
827
835
|
var startPosition = checkPositionBounds(positionX, positionY, this.bounds, limitToBounds, paddingValue, wrapperComponent);
|
|
836
|
+
var startTime = new Date().getTime();
|
|
828
837
|
// animation start timestamp
|
|
829
838
|
animate.call(this, velocityAnimationType, newAnimationTime, function (step) {
|
|
830
|
-
var
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
839
|
+
var frameTime = new Date().getTime() - startTime;
|
|
840
|
+
var animationProgress = frameTime / panReturnAnimationTime;
|
|
841
|
+
var returnAnimation = availableAnimations[panReturnAnimationType];
|
|
842
|
+
var customReturnStep = returnAnimation(animationProgress);
|
|
843
|
+
if (frameTime > panReturnAnimationTime ||
|
|
844
|
+
customReturnStep > 1 ||
|
|
845
|
+
customReturnStep === Infinity ||
|
|
846
|
+
customReturnStep === -Infinity)
|
|
834
847
|
customReturnStep = 1;
|
|
835
|
-
var currentPositionX = getPosition(lockAxisX, targetX, step, customReturnStep, minPositionX, maxPositionX, limitToBounds,
|
|
836
|
-
var currentPositionY = getPosition(lockAxisY, targetY, step, customReturnStep, minPositionY, maxPositionY, limitToBounds,
|
|
837
|
-
if (
|
|
838
|
-
_this.offsetY !== currentPositionY) {
|
|
848
|
+
var currentPositionX = getPosition(lockAxisX, targetX, step, customReturnStep, minPositionX, maxPositionX, limitToBounds, positionX, startPosition.x, minTargetX, maxTargetX);
|
|
849
|
+
var currentPositionY = getPosition(lockAxisY, targetY, step, customReturnStep, minPositionY, maxPositionY, limitToBounds, positionY, startPosition.y, minTargetY, maxTargetY);
|
|
850
|
+
if (positionX !== currentPositionX || positionY !== currentPositionY) {
|
|
839
851
|
// Save panned position
|
|
840
852
|
_this.stateProvider.positionX = currentPositionX;
|
|
841
853
|
_this.stateProvider.positionY = currentPositionY;
|
|
842
|
-
_this.offsetX = currentPositionX;
|
|
843
|
-
_this.offsetY = currentPositionY;
|
|
844
854
|
// apply animation changes
|
|
845
855
|
_this.applyTransformation();
|
|
846
856
|
}
|
|
@@ -860,18 +870,14 @@ function calculateVelocityStart(event) {
|
|
|
860
870
|
var clientX = position_1.clientX, clientY = position_1.clientY;
|
|
861
871
|
var distanceX = clientX - this.lastMousePosition.clientX;
|
|
862
872
|
var distanceY = clientY - this.lastMousePosition.clientY;
|
|
863
|
-
var wrapperToWindowScaleX = 2 - window.innerWidth / wrapperComponent.offsetWidth;
|
|
864
|
-
var scaleFactorX = Math.max(0.1, Math.min(0.4, wrapperToWindowScaleX));
|
|
865
|
-
var wrapperToWindowScaleY = 2 - window.innerHeight / wrapperComponent.offsetHeight;
|
|
866
|
-
var scaleFactorY = Math.max(0.1, Math.min(0.4, wrapperToWindowScaleY));
|
|
867
|
-
var scaledDistanceX = distanceX -
|
|
868
|
-
distanceX / Math.max(velocityMinSpeed, scale - scale * scaleFactorX);
|
|
869
|
-
var scaledDistanceY = distanceY -
|
|
870
|
-
distanceY / Math.max(velocityMinSpeed, scale - scale * scaleFactorY);
|
|
871
873
|
var interval = now - this.velocityTime;
|
|
872
|
-
var
|
|
873
|
-
var
|
|
874
|
-
var
|
|
874
|
+
var wrapperToWindowScaleX = 2 - wrapperComponent.offsetWidth / window.innerWidth;
|
|
875
|
+
var wrapperToWindowScaleY = 2 - wrapperComponent.offsetHeight / window.innerHeight;
|
|
876
|
+
var scaledX = 20 * Math.max(velocityMinSpeed, Math.min(2, wrapperToWindowScaleX));
|
|
877
|
+
var scaledY = 20 * Math.max(velocityMinSpeed, Math.min(2, wrapperToWindowScaleY));
|
|
878
|
+
var velocityX = (distanceX / interval) * velocitySensitivity * scale * scaledX;
|
|
879
|
+
var velocityY = (distanceY / interval) * velocitySensitivity * scale * scaledY;
|
|
880
|
+
var speed = distanceX * distanceX + distanceY * distanceY;
|
|
875
881
|
var velocity_1 = (Math.sqrt(speed) / interval) * velocitySensitivity;
|
|
876
882
|
if (this.velocity && velocity_1 < this.velocity.velocity && this.throttle)
|
|
877
883
|
return;
|
|
@@ -891,13 +897,17 @@ function calculateVelocityStart(event) {
|
|
|
891
897
|
function getPosition(isLocked, target, step, panReturnStep, minBound, maxBound, limitToBounds, offset, startPosition, minTarget, maxTarget) {
|
|
892
898
|
if (limitToBounds) {
|
|
893
899
|
if (startPosition > minBound && offset > maxBound) {
|
|
894
|
-
var newPosition = startPosition
|
|
900
|
+
var newPosition = startPosition - (startPosition - maxBound) * panReturnStep;
|
|
901
|
+
if (newPosition > maxTarget)
|
|
902
|
+
return maxTarget;
|
|
895
903
|
if (newPosition < maxBound)
|
|
896
904
|
return maxBound;
|
|
897
905
|
return newPosition;
|
|
898
906
|
}
|
|
899
907
|
if (startPosition < minBound && offset < minBound) {
|
|
900
|
-
var newPosition = startPosition
|
|
908
|
+
var newPosition = startPosition - (startPosition - minBound) * panReturnStep;
|
|
909
|
+
if (newPosition < minTarget)
|
|
910
|
+
return minTarget;
|
|
901
911
|
if (newPosition > minBound)
|
|
902
912
|
return minBound;
|
|
903
913
|
return newPosition;
|
|
@@ -905,7 +915,7 @@ function getPosition(isLocked, target, step, panReturnStep, minBound, maxBound,
|
|
|
905
915
|
}
|
|
906
916
|
if (isLocked)
|
|
907
917
|
return startPosition;
|
|
908
|
-
var offsetPosition = offset + target
|
|
918
|
+
var offsetPosition = offset + target * step;
|
|
909
919
|
return boundLimiter(offsetPosition, minBound, maxBound, limitToBounds);
|
|
910
920
|
}
|
|
911
921
|
|
|
@@ -1075,7 +1085,7 @@ var StateProvider = /** @class */ (function (_super) {
|
|
|
1075
1085
|
handleCallback(_this.props.onPanningStart, _this.getCallbackProps());
|
|
1076
1086
|
};
|
|
1077
1087
|
_this.handleStartPanning = function (event) {
|
|
1078
|
-
var _a = _this.stateProvider, wrapperComponent = _a.wrapperComponent, scale = _a.scale, _b = _a.options, minScale = _b.minScale, maxScale = _b.maxScale,
|
|
1088
|
+
var _a = _this.stateProvider, wrapperComponent = _a.wrapperComponent, scale = _a.scale, _b = _a.options, minScale = _b.minScale, maxScale = _b.maxScale, limitToWrapper = _b.limitToWrapper, disabled = _a.pan.disabled;
|
|
1079
1089
|
var target = event.target, touches = event.touches;
|
|
1080
1090
|
if (disabled ||
|
|
1081
1091
|
_this.stateProvider.options.disabled ||
|
|
@@ -1085,7 +1095,7 @@ var StateProvider = /** @class */ (function (_super) {
|
|
|
1085
1095
|
scale > maxScale)
|
|
1086
1096
|
return;
|
|
1087
1097
|
handleDisableAnimation.call(_this);
|
|
1088
|
-
_this.bounds = handleCalculateBounds.call(_this, scale,
|
|
1098
|
+
_this.bounds = handleCalculateBounds.call(_this, scale, limitToWrapper);
|
|
1089
1099
|
// Mobile points
|
|
1090
1100
|
if (touches && touches.length === 1) {
|
|
1091
1101
|
_this.handleSetUpPanning(touches[0].clientX, touches[0].clientY);
|
|
@@ -1302,14 +1312,35 @@ var StateProvider = /** @class */ (function (_super) {
|
|
|
1302
1312
|
};
|
|
1303
1313
|
_this.setContentComponent = function (contentComponent) {
|
|
1304
1314
|
_this.setState({ contentComponent: contentComponent }, function () {
|
|
1305
|
-
var _a = _this.stateProvider,
|
|
1306
|
-
var
|
|
1307
|
-
if (
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1315
|
+
var _a = _this.stateProvider, wrapperComponent = _a.wrapperComponent, _b = _a.options, centerContent = _b.centerContent, limitToBounds = _b.limitToBounds, limitToWrapper = _b.limitToWrapper, scale = _a.scale;
|
|
1316
|
+
var _c = _this.props.defaultValues, positionX = _c.positionX, positionY = _c.positionY;
|
|
1317
|
+
if ((limitToBounds && !limitToWrapper) ||
|
|
1318
|
+
(centerContent && !positionX && !positionY)) {
|
|
1319
|
+
var transform = "translate(25%, 25%) scale(" + scale + ")";
|
|
1320
|
+
contentComponent.style.transform = transform;
|
|
1321
|
+
contentComponent.style.WebkitTransform = transform;
|
|
1322
|
+
// force update to inject state to the context
|
|
1323
|
+
_this.forceUpdate();
|
|
1324
|
+
var startTime_1 = new Date().getTime();
|
|
1325
|
+
var maxTimeWait_1 = 2000;
|
|
1326
|
+
var interval_1 = setInterval(function () {
|
|
1327
|
+
if (wrapperComponent.offsetWidth) {
|
|
1328
|
+
var bounds = handleCalculateBounds.call(_this, scale, false);
|
|
1329
|
+
_this.stateProvider.positionX = bounds.minPositionX;
|
|
1330
|
+
_this.stateProvider.positionY = bounds.minPositionY;
|
|
1331
|
+
_this.applyTransformation(null, null, null);
|
|
1332
|
+
clearInterval(interval_1);
|
|
1333
|
+
interval_1 = null;
|
|
1334
|
+
}
|
|
1335
|
+
else if (new Date().getTime() - startTime_1 > maxTimeWait_1) {
|
|
1336
|
+
clearInterval(interval_1);
|
|
1337
|
+
interval_1 = null;
|
|
1338
|
+
}
|
|
1339
|
+
}, 20);
|
|
1340
|
+
}
|
|
1341
|
+
else {
|
|
1342
|
+
_this.applyTransformation(null, null, null);
|
|
1311
1343
|
}
|
|
1312
|
-
_this.applyTransformation(null, null, null);
|
|
1313
1344
|
});
|
|
1314
1345
|
};
|
|
1315
1346
|
_this.applyTransformation = function (newScale, posX, posY) {
|
|
@@ -1373,7 +1404,7 @@ var StateProvider = /** @class */ (function (_super) {
|
|
|
1373
1404
|
// set bound for animations
|
|
1374
1405
|
if ((wrapperComponent && contentComponent) ||
|
|
1375
1406
|
oldProps.dynamicValues !== dynamicValues) {
|
|
1376
|
-
this.maxBounds = handleCalculateBounds.call(this, this.stateProvider.scale, this.stateProvider.
|
|
1407
|
+
this.maxBounds = handleCalculateBounds.call(this, this.stateProvider.scale, this.stateProvider.options.limitToWrapper);
|
|
1377
1408
|
}
|
|
1378
1409
|
// must be at the end of the update function, updates
|
|
1379
1410
|
if (oldProps.dynamicValues && oldProps.dynamicValues !== dynamicValues) {
|
|
@@ -1383,10 +1414,12 @@ var StateProvider = /** @class */ (function (_super) {
|
|
|
1383
1414
|
}
|
|
1384
1415
|
};
|
|
1385
1416
|
StateProvider.prototype.render = function () {
|
|
1417
|
+
var _a = this.state, wrapperComponent = _a.wrapperComponent, contentComponent = _a.contentComponent;
|
|
1386
1418
|
/**
|
|
1387
1419
|
* Context provider value
|
|
1388
1420
|
*/
|
|
1389
1421
|
var value = {
|
|
1422
|
+
loaded: Boolean(wrapperComponent && contentComponent),
|
|
1390
1423
|
state: this.getCallbackProps(),
|
|
1391
1424
|
dispatch: {
|
|
1392
1425
|
setScale: this.setScale,
|
|
@@ -1414,11 +1447,15 @@ var StateProvider = /** @class */ (function (_super) {
|
|
|
1414
1447
|
|
|
1415
1448
|
var TransformWrapper = function (_a) {
|
|
1416
1449
|
var children = _a.children, defaultPositionX = _a.defaultPositionX, defaultPositionY = _a.defaultPositionY, defaultScale = _a.defaultScale, onWheelStart = _a.onWheelStart, onWheel = _a.onWheel, onWheelStop = _a.onWheelStop, onPanningStart = _a.onPanningStart, onPanning = _a.onPanning, onPanningStop = _a.onPanningStop, onPinchingStart = _a.onPinchingStart, onPinching = _a.onPinching, onPinchingStop = _a.onPinchingStop, onZoomChange = _a.onZoomChange, rest = __rest(_a, ["children", "defaultPositionX", "defaultPositionY", "defaultScale", "onWheelStart", "onWheel", "onWheelStop", "onPanningStart", "onPanning", "onPanningStop", "onPinchingStart", "onPinching", "onPinchingStop", "onZoomChange"]);
|
|
1450
|
+
var props = __assign({}, rest);
|
|
1451
|
+
if (props.options && props.options.limitToWrapper) {
|
|
1452
|
+
props.options.limitToBounds = true;
|
|
1453
|
+
}
|
|
1417
1454
|
return (React__default.createElement(StateProvider, { defaultValues: deleteUndefinedProps({
|
|
1418
1455
|
positionX: defaultPositionX,
|
|
1419
1456
|
positionY: defaultPositionY,
|
|
1420
1457
|
scale: defaultScale,
|
|
1421
|
-
}), dynamicValues: deleteUndefinedProps(getValidPropsFromObject(
|
|
1458
|
+
}), dynamicValues: deleteUndefinedProps(getValidPropsFromObject(props)), onWheelStart: onWheelStart, onWheel: onWheel, onWheelStop: onWheelStop, onPanningStart: onPanningStart, onPanning: onPanning, onPanningStop: onPanningStop, onPinchingStart: onPinchingStart, onPinching: onPinching, onPinchingStop: onPinchingStop, onZoomChange: onZoomChange }, children));
|
|
1422
1459
|
};
|
|
1423
1460
|
|
|
1424
1461
|
function styleInject(css, ref) {
|