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/README.md
CHANGED
|
@@ -134,6 +134,7 @@ class Example extends Component {
|
|
|
134
134
|
| minScale | 1 | number |
|
|
135
135
|
| maxScale | 8 | number |
|
|
136
136
|
| limitToBounds | true | boolean |
|
|
137
|
+
| limitToWrapper | false | boolean |
|
|
137
138
|
| centerContent | true | boolean |
|
|
138
139
|
|
|
139
140
|
#### scalePadding prop elements
|
|
@@ -147,13 +148,13 @@ class Example extends Component {
|
|
|
147
148
|
|
|
148
149
|
#### Wheel prop elements
|
|
149
150
|
|
|
150
|
-
| Props
|
|
151
|
-
|
|
|
152
|
-
| disabled
|
|
153
|
-
| step
|
|
154
|
-
| wheelEnabled
|
|
155
|
-
| touchPadEnabled
|
|
156
|
-
|
|
|
151
|
+
| Props | Default | Type |
|
|
152
|
+
| :-------------- | :-----: | ------: |
|
|
153
|
+
| disabled | false | boolean |
|
|
154
|
+
| step | 6.5 | number |
|
|
155
|
+
| wheelEnabled | true | boolean |
|
|
156
|
+
| touchPadEnabled | true | boolean |
|
|
157
|
+
| limitsOnWheel | true | boolean |
|
|
157
158
|
|
|
158
159
|
#### Pan prop elements
|
|
159
160
|
|
|
@@ -169,7 +170,6 @@ class Example extends Component {
|
|
|
169
170
|
| velocityMinSpeed | 1.2 | number |
|
|
170
171
|
| velocityBaseTime | 1800 | number |
|
|
171
172
|
| velocityAnimationType | easeOut | string |
|
|
172
|
-
| limitToWrapperBounds | false | boolean |
|
|
173
173
|
| padding | true | boolean |
|
|
174
174
|
| paddingSize | 40 | number |
|
|
175
175
|
| animationTime | 200 | number |
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
declare const TransformWrapper: ({ children, defaultPositionX, defaultPositionY, defaultScale, onWheelStart, onWheel, onWheelStop, onPanningStart, onPanning, onPanningStop, onPinchingStart, onPinching, onPinchingStop, onZoomChange, ...rest }:
|
|
2
|
+
import { PropsList } from "../store/interfaces/propsInterface";
|
|
3
|
+
declare const TransformWrapper: ({ children, defaultPositionX, defaultPositionY, defaultScale, onWheelStart, onWheel, onWheelStop, onPanningStart, onPanning, onPanningStop, onPinchingStart, onPinching, onPinchingStop, onZoomChange, ...rest }: PropsList) => JSX.Element;
|
|
4
4
|
export { TransformWrapper };
|
package/dist/index.es.js
CHANGED
|
@@ -69,6 +69,7 @@ var initialState = {
|
|
|
69
69
|
minScale: 1,
|
|
70
70
|
maxScale: 8,
|
|
71
71
|
limitToBounds: true,
|
|
72
|
+
limitToWrapper: false,
|
|
72
73
|
centerContent: true,
|
|
73
74
|
wrapperClass: "",
|
|
74
75
|
contentClass: "",
|
|
@@ -78,7 +79,7 @@ var initialState = {
|
|
|
78
79
|
step: 5,
|
|
79
80
|
wheelEnabled: true,
|
|
80
81
|
touchPadEnabled: true,
|
|
81
|
-
|
|
82
|
+
limitsOnWheel: false,
|
|
82
83
|
},
|
|
83
84
|
pan: {
|
|
84
85
|
disabled: false,
|
|
@@ -87,15 +88,14 @@ var initialState = {
|
|
|
87
88
|
lockAxisY: false,
|
|
88
89
|
velocity: true,
|
|
89
90
|
velocityEqualToMove: true,
|
|
90
|
-
velocitySensitivity:
|
|
91
|
+
velocitySensitivity: 2,
|
|
91
92
|
velocityActiveScale: 1,
|
|
92
|
-
velocityMinSpeed:
|
|
93
|
+
velocityMinSpeed: 1,
|
|
93
94
|
velocityBaseTime: 1600,
|
|
94
|
-
velocityAnimationType: "
|
|
95
|
-
limitToWrapperBounds: false,
|
|
95
|
+
velocityAnimationType: "easeOutQuart",
|
|
96
96
|
padding: true,
|
|
97
97
|
paddingSize: 30,
|
|
98
|
-
panReturnAnimationTime:
|
|
98
|
+
panReturnAnimationTime: 400,
|
|
99
99
|
panReturnAnimationType: "easeOut",
|
|
100
100
|
disableOnTarget: [],
|
|
101
101
|
},
|
|
@@ -172,12 +172,12 @@ var boundLimiter = function (value, minBound, maxBound, isActive) {
|
|
|
172
172
|
/**
|
|
173
173
|
* Calculate bounding area of zoomed/panned element
|
|
174
174
|
*/
|
|
175
|
-
var calculateBoundingArea = function (wrapperWidth, newContentWidth, diffWidth, wrapperHeight, newContentHeight, diffHeight,
|
|
175
|
+
var calculateBoundingArea = function (wrapperWidth, newContentWidth, diffWidth, wrapperHeight, newContentHeight, diffHeight, limitToWrapper) {
|
|
176
176
|
var scaleWidthFactor = wrapperWidth > newContentWidth
|
|
177
|
-
? diffWidth * (
|
|
177
|
+
? diffWidth * (limitToWrapper ? 1 : 0.5)
|
|
178
178
|
: 0;
|
|
179
179
|
var scaleHeightFactor = wrapperHeight > newContentHeight
|
|
180
|
-
? diffHeight * (
|
|
180
|
+
? diffHeight * (limitToWrapper ? 1 : 0.5)
|
|
181
181
|
: 0;
|
|
182
182
|
var minPositionX = wrapperWidth - newContentWidth - scaleWidthFactor;
|
|
183
183
|
var maxPositionX = scaleWidthFactor;
|
|
@@ -509,7 +509,7 @@ function handlePanningAnimation() {
|
|
|
509
509
|
});
|
|
510
510
|
}
|
|
511
511
|
function handlePanToBounds() {
|
|
512
|
-
var _a = this.stateProvider, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale, _b = _a.options, disabled = _b.disabled, limitToBounds = _b.limitToBounds;
|
|
512
|
+
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;
|
|
513
513
|
var wrapperComponent = this.state.wrapperComponent;
|
|
514
514
|
if (disabled)
|
|
515
515
|
return;
|
|
@@ -524,7 +524,7 @@ function handlePanToBounds() {
|
|
|
524
524
|
: this.stateProvider.minPositionY || 0;
|
|
525
525
|
var mousePosX = mouseX;
|
|
526
526
|
var mousePosY = mouseY;
|
|
527
|
-
var _d = handleCalculatePositions.call(this, mousePosX, mousePosY, scale, this.bounds, limitToBounds), x = _d.x, y = _d.y;
|
|
527
|
+
var _d = handleCalculatePositions.call(this, mousePosX, mousePosY, scale, this.bounds, limitToBounds || limitToWrapper), x = _d.x, y = _d.y;
|
|
528
528
|
return {
|
|
529
529
|
scale: scale,
|
|
530
530
|
positionX: xChanged ? x : positionX,
|
|
@@ -574,7 +574,7 @@ function handleCalculateBounds(newScale, limitToWrapper) {
|
|
|
574
574
|
* Wheel zoom event
|
|
575
575
|
*/
|
|
576
576
|
function handleWheelZoom(event) {
|
|
577
|
-
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,
|
|
577
|
+
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;
|
|
578
578
|
event.preventDefault();
|
|
579
579
|
event.stopPropagation();
|
|
580
580
|
var delta = getDelta(event, null);
|
|
@@ -582,9 +582,9 @@ function handleWheelZoom(event) {
|
|
|
582
582
|
// if scale not change
|
|
583
583
|
if (scale === newScale)
|
|
584
584
|
return;
|
|
585
|
-
var bounds = handleCalculateBounds.call(this, newScale,
|
|
585
|
+
var bounds = handleCalculateBounds.call(this, newScale, !limitsOnWheel);
|
|
586
586
|
var _d = wheelMousePosition(event, contentComponent, scale), mouseX = _d.mouseX, mouseY = _d.mouseY;
|
|
587
|
-
var isLimitedToBounds = limitToBounds && (disabled || size === 0 ||
|
|
587
|
+
var isLimitedToBounds = limitToBounds && (disabled || size === 0 || limitsOnWheel);
|
|
588
588
|
var _e = handleCalculatePositions.call(this, mouseX, mouseY, newScale, bounds, isLimitedToBounds), x = _e.x, y = _e.y;
|
|
589
589
|
this.bounds = bounds;
|
|
590
590
|
this.stateProvider.previousScale = scale;
|
|
@@ -597,11 +597,11 @@ function handleWheelZoom(event) {
|
|
|
597
597
|
* Zoom for animations
|
|
598
598
|
*/
|
|
599
599
|
function handleZoomToPoint(isDisabled, scale, mouseX, mouseY, event) {
|
|
600
|
-
var _a = this.stateProvider, contentComponent = _a.contentComponent, _b = _a.options, disabled = _b.disabled, minScale = _b.minScale, maxScale = _b.maxScale, limitToBounds = _b.limitToBounds;
|
|
600
|
+
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;
|
|
601
601
|
if (disabled || isDisabled)
|
|
602
602
|
return;
|
|
603
603
|
var newScale = checkZoomBounds(roundNumber(scale, 2), minScale, maxScale, null, null);
|
|
604
|
-
var bounds = handleCalculateBounds.call(this, newScale,
|
|
604
|
+
var bounds = handleCalculateBounds.call(this, newScale, limitToWrapper);
|
|
605
605
|
var mousePosX = mouseX;
|
|
606
606
|
var mousePosY = mouseY;
|
|
607
607
|
// if event is present - use it's mouse position
|
|
@@ -614,9 +614,9 @@ function handleZoomToPoint(isDisabled, scale, mouseX, mouseY, event) {
|
|
|
614
614
|
return { scale: newScale, positionX: x, positionY: y };
|
|
615
615
|
}
|
|
616
616
|
function handlePaddingAnimation$1() {
|
|
617
|
-
var _a = this.stateProvider, scale = _a.scale, wrapperComponent = _a.wrapperComponent,
|
|
617
|
+
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;
|
|
618
618
|
var isDisabled = disabled || scale >= minScale;
|
|
619
|
-
if (scale >= 1) {
|
|
619
|
+
if (scale >= 1 || limitToBounds) {
|
|
620
620
|
// fire fit to bounds animation
|
|
621
621
|
handlePanningAnimation.call(this);
|
|
622
622
|
}
|
|
@@ -659,8 +659,8 @@ function handleZoomControls(customDelta, customStep) {
|
|
|
659
659
|
var _a = this.stateProvider, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY, wrapperComponent = _a.wrapperComponent, zoomIn = _a.zoomIn, zoomOut = _a.zoomOut;
|
|
660
660
|
var wrapperWidth = wrapperComponent.offsetWidth;
|
|
661
661
|
var wrapperHeight = wrapperComponent.offsetHeight;
|
|
662
|
-
var mouseX = (
|
|
663
|
-
var mouseY = (
|
|
662
|
+
var mouseX = (wrapperWidth / 2 - positionX) / scale;
|
|
663
|
+
var mouseY = (wrapperHeight / 2 - positionY) / scale;
|
|
664
664
|
var newScale = handleCalculateZoom.call(this, customDelta, customStep, undefined, undefined, true);
|
|
665
665
|
var isZoomIn = newScale > scale;
|
|
666
666
|
var animationSpeed = isZoomIn
|
|
@@ -681,7 +681,7 @@ function handleZoomControls(customDelta, customStep) {
|
|
|
681
681
|
}
|
|
682
682
|
function resetTransformations(animationSpeed) {
|
|
683
683
|
var _a = this.props.defaultValues, defaultScale = _a.defaultScale, defaultPositionX = _a.defaultPositionX, defaultPositionY = _a.defaultPositionY;
|
|
684
|
-
var _b = this.stateProvider, scale = _b.scale, positionX = _b.positionX, positionY = _b.positionY,
|
|
684
|
+
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;
|
|
685
685
|
if (disabled || reset.disabled)
|
|
686
686
|
return;
|
|
687
687
|
if (scale === defaultScale &&
|
|
@@ -692,6 +692,11 @@ function resetTransformations(animationSpeed) {
|
|
|
692
692
|
var targetScale = checkIsNumber(defaultScale, initialState.scale);
|
|
693
693
|
var newPositionX = checkIsNumber(defaultPositionX, initialState.positionX);
|
|
694
694
|
var newPositionY = checkIsNumber(defaultPositionY, initialState.positionY);
|
|
695
|
+
if ((limitToBounds && !limitToWrapper) || centerContent) {
|
|
696
|
+
var bounds = handleCalculateBounds.call(this, targetScale, limitToWrapper);
|
|
697
|
+
newPositionX = bounds.minPositionX;
|
|
698
|
+
newPositionY = bounds.minPositionY;
|
|
699
|
+
}
|
|
695
700
|
var targetState = {
|
|
696
701
|
scale: targetScale,
|
|
697
702
|
positionX: newPositionX,
|
|
@@ -741,7 +746,7 @@ function calculateMidpoint(event, scale, contentComponent) {
|
|
|
741
746
|
};
|
|
742
747
|
}
|
|
743
748
|
function handleZoomPinch(event) {
|
|
744
|
-
var _a = this.stateProvider, scale = _a.scale,
|
|
749
|
+
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;
|
|
745
750
|
var contentComponent = this.state.contentComponent;
|
|
746
751
|
if (pinch.disabled || this.stateProvider.options.disabled)
|
|
747
752
|
return;
|
|
@@ -753,7 +758,7 @@ function handleZoomPinch(event) {
|
|
|
753
758
|
if (this.pinchStartDistance === null)
|
|
754
759
|
return;
|
|
755
760
|
// Position transformation
|
|
756
|
-
var
|
|
761
|
+
var _d = calculateMidpoint(event, scale, contentComponent), mouseX = _d.mouseX, mouseY = _d.mouseY;
|
|
757
762
|
// if touches goes off of the wrapper element
|
|
758
763
|
if (checkIfInfinite(mouseX) || checkIfInfinite(mouseY))
|
|
759
764
|
return;
|
|
@@ -762,10 +767,10 @@ function handleZoomPinch(event) {
|
|
|
762
767
|
if (checkIfInfinite(newScale) || newScale === scale)
|
|
763
768
|
return;
|
|
764
769
|
// Get new element sizes to calculate bounds
|
|
765
|
-
var bounds = handleCalculateBounds.call(this, newScale);
|
|
770
|
+
var bounds = handleCalculateBounds.call(this, newScale, limitToWrapper);
|
|
766
771
|
// Calculate transformations
|
|
767
|
-
var isLimitedToBounds = limitToBounds && (disabled || size === 0 ||
|
|
768
|
-
var
|
|
772
|
+
var isLimitedToBounds = limitToBounds && (disabled || size === 0 || limitsOnWheel);
|
|
773
|
+
var _e = handleCalculatePositions.call(this, mouseX, mouseY, newScale, bounds, isLimitedToBounds), x = _e.x, y = _e.y;
|
|
769
774
|
this.lastDistance = currentDistance;
|
|
770
775
|
this.stateProvider.positionX = x;
|
|
771
776
|
this.stateProvider.positionY = y;
|
|
@@ -791,7 +796,7 @@ function handleFireVelocity() {
|
|
|
791
796
|
}
|
|
792
797
|
function animateVelocity() {
|
|
793
798
|
var _this = this;
|
|
794
|
-
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;
|
|
799
|
+
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;
|
|
795
800
|
if (!this.mounted)
|
|
796
801
|
return;
|
|
797
802
|
if (!this.velocity || !this.bounds)
|
|
@@ -805,35 +810,40 @@ function animateVelocity() {
|
|
|
805
810
|
}
|
|
806
811
|
var targetX = velocityX;
|
|
807
812
|
var targetY = velocityY;
|
|
808
|
-
this.offsetX = positionX;
|
|
809
|
-
this.offsetY = positionY;
|
|
810
813
|
// pan return animation
|
|
811
814
|
var newAnimationTime = animationTime > panReturnAnimationTime
|
|
812
815
|
? animationTime
|
|
813
816
|
: panReturnAnimationTime;
|
|
814
|
-
var isReturnAnimationLonger = animationTime < panReturnAnimationTime;
|
|
815
|
-
var maxTargetX = positionX - maxPositionX;
|
|
816
|
-
var minTargetX = positionX - minPositionX;
|
|
817
|
-
var maxTargetY = positionY - maxPositionY;
|
|
818
|
-
var minTargetY = positionY - minPositionY;
|
|
819
817
|
var paddingValue = padding ? paddingSize : 0;
|
|
818
|
+
var paddingX = wrapperComponent
|
|
819
|
+
? (paddingValue * wrapperComponent.offsetWidth) / 100
|
|
820
|
+
: 0;
|
|
821
|
+
var paddingY = wrapperComponent
|
|
822
|
+
? (paddingValue * wrapperComponent.offsetHeight) / 100
|
|
823
|
+
: 0;
|
|
824
|
+
var maxTargetX = maxPositionX + paddingX;
|
|
825
|
+
var minTargetX = minPositionX - paddingX;
|
|
826
|
+
var maxTargetY = maxPositionY + paddingY;
|
|
827
|
+
var minTargetY = minPositionY - paddingY;
|
|
820
828
|
var startPosition = checkPositionBounds(positionX, positionY, this.bounds, limitToBounds, paddingValue, wrapperComponent);
|
|
829
|
+
var startTime = new Date().getTime();
|
|
821
830
|
// animation start timestamp
|
|
822
831
|
animate.call(this, velocityAnimationType, newAnimationTime, function (step) {
|
|
823
|
-
var
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
832
|
+
var frameTime = new Date().getTime() - startTime;
|
|
833
|
+
var animationProgress = frameTime / panReturnAnimationTime;
|
|
834
|
+
var returnAnimation = availableAnimations[panReturnAnimationType];
|
|
835
|
+
var customReturnStep = returnAnimation(animationProgress);
|
|
836
|
+
if (frameTime > panReturnAnimationTime ||
|
|
837
|
+
customReturnStep > 1 ||
|
|
838
|
+
customReturnStep === Infinity ||
|
|
839
|
+
customReturnStep === -Infinity)
|
|
827
840
|
customReturnStep = 1;
|
|
828
|
-
var currentPositionX = getPosition(lockAxisX, targetX, step, customReturnStep, minPositionX, maxPositionX, limitToBounds,
|
|
829
|
-
var currentPositionY = getPosition(lockAxisY, targetY, step, customReturnStep, minPositionY, maxPositionY, limitToBounds,
|
|
830
|
-
if (
|
|
831
|
-
_this.offsetY !== currentPositionY) {
|
|
841
|
+
var currentPositionX = getPosition(lockAxisX, targetX, step, customReturnStep, minPositionX, maxPositionX, limitToBounds, positionX, startPosition.x, minTargetX, maxTargetX);
|
|
842
|
+
var currentPositionY = getPosition(lockAxisY, targetY, step, customReturnStep, minPositionY, maxPositionY, limitToBounds, positionY, startPosition.y, minTargetY, maxTargetY);
|
|
843
|
+
if (positionX !== currentPositionX || positionY !== currentPositionY) {
|
|
832
844
|
// Save panned position
|
|
833
845
|
_this.stateProvider.positionX = currentPositionX;
|
|
834
846
|
_this.stateProvider.positionY = currentPositionY;
|
|
835
|
-
_this.offsetX = currentPositionX;
|
|
836
|
-
_this.offsetY = currentPositionY;
|
|
837
847
|
// apply animation changes
|
|
838
848
|
_this.applyTransformation();
|
|
839
849
|
}
|
|
@@ -853,18 +863,14 @@ function calculateVelocityStart(event) {
|
|
|
853
863
|
var clientX = position_1.clientX, clientY = position_1.clientY;
|
|
854
864
|
var distanceX = clientX - this.lastMousePosition.clientX;
|
|
855
865
|
var distanceY = clientY - this.lastMousePosition.clientY;
|
|
856
|
-
var wrapperToWindowScaleX = 2 - window.innerWidth / wrapperComponent.offsetWidth;
|
|
857
|
-
var scaleFactorX = Math.max(0.1, Math.min(0.4, wrapperToWindowScaleX));
|
|
858
|
-
var wrapperToWindowScaleY = 2 - window.innerHeight / wrapperComponent.offsetHeight;
|
|
859
|
-
var scaleFactorY = Math.max(0.1, Math.min(0.4, wrapperToWindowScaleY));
|
|
860
|
-
var scaledDistanceX = distanceX -
|
|
861
|
-
distanceX / Math.max(velocityMinSpeed, scale - scale * scaleFactorX);
|
|
862
|
-
var scaledDistanceY = distanceY -
|
|
863
|
-
distanceY / Math.max(velocityMinSpeed, scale - scale * scaleFactorY);
|
|
864
866
|
var interval = now - this.velocityTime;
|
|
865
|
-
var
|
|
866
|
-
var
|
|
867
|
-
var
|
|
867
|
+
var wrapperToWindowScaleX = 2 - wrapperComponent.offsetWidth / window.innerWidth;
|
|
868
|
+
var wrapperToWindowScaleY = 2 - wrapperComponent.offsetHeight / window.innerHeight;
|
|
869
|
+
var scaledX = 20 * Math.max(velocityMinSpeed, Math.min(2, wrapperToWindowScaleX));
|
|
870
|
+
var scaledY = 20 * Math.max(velocityMinSpeed, Math.min(2, wrapperToWindowScaleY));
|
|
871
|
+
var velocityX = (distanceX / interval) * velocitySensitivity * scale * scaledX;
|
|
872
|
+
var velocityY = (distanceY / interval) * velocitySensitivity * scale * scaledY;
|
|
873
|
+
var speed = distanceX * distanceX + distanceY * distanceY;
|
|
868
874
|
var velocity_1 = (Math.sqrt(speed) / interval) * velocitySensitivity;
|
|
869
875
|
if (this.velocity && velocity_1 < this.velocity.velocity && this.throttle)
|
|
870
876
|
return;
|
|
@@ -884,13 +890,17 @@ function calculateVelocityStart(event) {
|
|
|
884
890
|
function getPosition(isLocked, target, step, panReturnStep, minBound, maxBound, limitToBounds, offset, startPosition, minTarget, maxTarget) {
|
|
885
891
|
if (limitToBounds) {
|
|
886
892
|
if (startPosition > minBound && offset > maxBound) {
|
|
887
|
-
var newPosition = startPosition
|
|
893
|
+
var newPosition = startPosition - (startPosition - maxBound) * panReturnStep;
|
|
894
|
+
if (newPosition > maxTarget)
|
|
895
|
+
return maxTarget;
|
|
888
896
|
if (newPosition < maxBound)
|
|
889
897
|
return maxBound;
|
|
890
898
|
return newPosition;
|
|
891
899
|
}
|
|
892
900
|
if (startPosition < minBound && offset < minBound) {
|
|
893
|
-
var newPosition = startPosition
|
|
901
|
+
var newPosition = startPosition - (startPosition - minBound) * panReturnStep;
|
|
902
|
+
if (newPosition < minTarget)
|
|
903
|
+
return minTarget;
|
|
894
904
|
if (newPosition > minBound)
|
|
895
905
|
return minBound;
|
|
896
906
|
return newPosition;
|
|
@@ -898,7 +908,7 @@ function getPosition(isLocked, target, step, panReturnStep, minBound, maxBound,
|
|
|
898
908
|
}
|
|
899
909
|
if (isLocked)
|
|
900
910
|
return startPosition;
|
|
901
|
-
var offsetPosition = offset + target
|
|
911
|
+
var offsetPosition = offset + target * step;
|
|
902
912
|
return boundLimiter(offsetPosition, minBound, maxBound, limitToBounds);
|
|
903
913
|
}
|
|
904
914
|
|
|
@@ -1068,7 +1078,7 @@ var StateProvider = /** @class */ (function (_super) {
|
|
|
1068
1078
|
handleCallback(_this.props.onPanningStart, _this.getCallbackProps());
|
|
1069
1079
|
};
|
|
1070
1080
|
_this.handleStartPanning = function (event) {
|
|
1071
|
-
var _a = _this.stateProvider, wrapperComponent = _a.wrapperComponent, scale = _a.scale, _b = _a.options, minScale = _b.minScale, maxScale = _b.maxScale,
|
|
1081
|
+
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;
|
|
1072
1082
|
var target = event.target, touches = event.touches;
|
|
1073
1083
|
if (disabled ||
|
|
1074
1084
|
_this.stateProvider.options.disabled ||
|
|
@@ -1078,7 +1088,7 @@ var StateProvider = /** @class */ (function (_super) {
|
|
|
1078
1088
|
scale > maxScale)
|
|
1079
1089
|
return;
|
|
1080
1090
|
handleDisableAnimation.call(_this);
|
|
1081
|
-
_this.bounds = handleCalculateBounds.call(_this, scale,
|
|
1091
|
+
_this.bounds = handleCalculateBounds.call(_this, scale, limitToWrapper);
|
|
1082
1092
|
// Mobile points
|
|
1083
1093
|
if (touches && touches.length === 1) {
|
|
1084
1094
|
_this.handleSetUpPanning(touches[0].clientX, touches[0].clientY);
|
|
@@ -1295,14 +1305,35 @@ var StateProvider = /** @class */ (function (_super) {
|
|
|
1295
1305
|
};
|
|
1296
1306
|
_this.setContentComponent = function (contentComponent) {
|
|
1297
1307
|
_this.setState({ contentComponent: contentComponent }, function () {
|
|
1298
|
-
var _a = _this.stateProvider,
|
|
1299
|
-
var
|
|
1300
|
-
if (
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1308
|
+
var _a = _this.stateProvider, wrapperComponent = _a.wrapperComponent, _b = _a.options, centerContent = _b.centerContent, limitToBounds = _b.limitToBounds, limitToWrapper = _b.limitToWrapper, scale = _a.scale;
|
|
1309
|
+
var _c = _this.props.defaultValues, positionX = _c.positionX, positionY = _c.positionY;
|
|
1310
|
+
if ((limitToBounds && !limitToWrapper) ||
|
|
1311
|
+
(centerContent && !positionX && !positionY)) {
|
|
1312
|
+
var transform = "translate(25%, 25%) scale(" + scale + ")";
|
|
1313
|
+
contentComponent.style.transform = transform;
|
|
1314
|
+
contentComponent.style.WebkitTransform = transform;
|
|
1315
|
+
// force update to inject state to the context
|
|
1316
|
+
_this.forceUpdate();
|
|
1317
|
+
var startTime_1 = new Date().getTime();
|
|
1318
|
+
var maxTimeWait_1 = 2000;
|
|
1319
|
+
var interval_1 = setInterval(function () {
|
|
1320
|
+
if (wrapperComponent.offsetWidth) {
|
|
1321
|
+
var bounds = handleCalculateBounds.call(_this, scale, false);
|
|
1322
|
+
_this.stateProvider.positionX = bounds.minPositionX;
|
|
1323
|
+
_this.stateProvider.positionY = bounds.minPositionY;
|
|
1324
|
+
_this.applyTransformation(null, null, null);
|
|
1325
|
+
clearInterval(interval_1);
|
|
1326
|
+
interval_1 = null;
|
|
1327
|
+
}
|
|
1328
|
+
else if (new Date().getTime() - startTime_1 > maxTimeWait_1) {
|
|
1329
|
+
clearInterval(interval_1);
|
|
1330
|
+
interval_1 = null;
|
|
1331
|
+
}
|
|
1332
|
+
}, 20);
|
|
1333
|
+
}
|
|
1334
|
+
else {
|
|
1335
|
+
_this.applyTransformation(null, null, null);
|
|
1304
1336
|
}
|
|
1305
|
-
_this.applyTransformation(null, null, null);
|
|
1306
1337
|
});
|
|
1307
1338
|
};
|
|
1308
1339
|
_this.applyTransformation = function (newScale, posX, posY) {
|
|
@@ -1366,7 +1397,7 @@ var StateProvider = /** @class */ (function (_super) {
|
|
|
1366
1397
|
// set bound for animations
|
|
1367
1398
|
if ((wrapperComponent && contentComponent) ||
|
|
1368
1399
|
oldProps.dynamicValues !== dynamicValues) {
|
|
1369
|
-
this.maxBounds = handleCalculateBounds.call(this, this.stateProvider.scale, this.stateProvider.
|
|
1400
|
+
this.maxBounds = handleCalculateBounds.call(this, this.stateProvider.scale, this.stateProvider.options.limitToWrapper);
|
|
1370
1401
|
}
|
|
1371
1402
|
// must be at the end of the update function, updates
|
|
1372
1403
|
if (oldProps.dynamicValues && oldProps.dynamicValues !== dynamicValues) {
|
|
@@ -1376,10 +1407,12 @@ var StateProvider = /** @class */ (function (_super) {
|
|
|
1376
1407
|
}
|
|
1377
1408
|
};
|
|
1378
1409
|
StateProvider.prototype.render = function () {
|
|
1410
|
+
var _a = this.state, wrapperComponent = _a.wrapperComponent, contentComponent = _a.contentComponent;
|
|
1379
1411
|
/**
|
|
1380
1412
|
* Context provider value
|
|
1381
1413
|
*/
|
|
1382
1414
|
var value = {
|
|
1415
|
+
loaded: Boolean(wrapperComponent && contentComponent),
|
|
1383
1416
|
state: this.getCallbackProps(),
|
|
1384
1417
|
dispatch: {
|
|
1385
1418
|
setScale: this.setScale,
|
|
@@ -1407,11 +1440,15 @@ var StateProvider = /** @class */ (function (_super) {
|
|
|
1407
1440
|
|
|
1408
1441
|
var TransformWrapper = function (_a) {
|
|
1409
1442
|
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"]);
|
|
1443
|
+
var props = __assign({}, rest);
|
|
1444
|
+
if (props.options && props.options.limitToWrapper) {
|
|
1445
|
+
props.options.limitToBounds = true;
|
|
1446
|
+
}
|
|
1410
1447
|
return (React.createElement(StateProvider, { defaultValues: deleteUndefinedProps({
|
|
1411
1448
|
positionX: defaultPositionX,
|
|
1412
1449
|
positionY: defaultPositionY,
|
|
1413
1450
|
scale: defaultScale,
|
|
1414
|
-
}), dynamicValues: deleteUndefinedProps(getValidPropsFromObject(
|
|
1451
|
+
}), 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));
|
|
1415
1452
|
};
|
|
1416
1453
|
|
|
1417
1454
|
function styleInject(css, ref) {
|