react-zoom-pan-pinch 2.3.2 → 2.5.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/components/transform-wrapper.d.ts +1 -3
- package/dist/constants/state.constants.d.ts +1 -4
- package/dist/core/double-click/double-click.logic.d.ts +2 -0
- package/dist/core/handlers/handlers.utils.d.ts +6 -5
- package/dist/core/instance.core.d.ts +4 -2
- package/dist/index.cjs.js +130 -106
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +70 -69
- package/dist/index.esm.js +131 -107
- package/dist/index.esm.js.map +1 -1
- package/dist/models/context.model.d.ts +0 -1
- package/dist/stories/examples/svg-zoom-to-element/example.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/transform-component.tsx +3 -3
- package/src/components/transform-wrapper.tsx +25 -26
- package/src/constants/state.constants.ts +1 -16
- package/src/core/animations/animations.utils.ts +1 -0
- package/src/core/double-click/double-click.logic.ts +55 -8
- package/src/core/handlers/handlers.logic.ts +1 -7
- package/src/core/handlers/handlers.utils.ts +30 -37
- package/src/core/instance.core.ts +15 -5
- package/src/hooks/use-transform-context.tsx +10 -3
- package/src/models/context.model.ts +0 -1
- package/src/stories/docs/props.tsx +0 -6
- package/src/stories/examples/controls/controls.stories.mdx +1 -0
- package/src/stories/examples/svg-zoom-to-element/creativity.svg +143 -0
- package/src/stories/examples/svg-zoom-to-element/example.tsx +57 -0
- package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +28 -0
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ZoomPanPinch } from "../core/instance.core";
|
|
3
3
|
import { ReactZoomPanPinchProps, ReactZoomPanPinchRef } from "../models";
|
|
4
|
-
export declare const Context: React.Context<
|
|
5
|
-
contextInstance: ZoomPanPinch | null;
|
|
6
|
-
}>;
|
|
4
|
+
export declare const Context: React.Context<ZoomPanPinch>;
|
|
7
5
|
export declare const TransformWrapper: React.ForwardRefExoticComponent<Omit<ReactZoomPanPinchProps, "ref"> & React.RefAttributes<ReactZoomPanPinchRef>>;
|
|
8
6
|
export default TransformWrapper;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { LibrarySetup,
|
|
1
|
+
import { LibrarySetup, ReactZoomPanPinchState } from "../models/context.model";
|
|
2
2
|
export declare const initialState: ReactZoomPanPinchState;
|
|
3
|
-
export declare const contextInitialState: ReactZoomPanPinchComponentHelpers & ReactZoomPanPinchState & {
|
|
4
|
-
contextInstance: ReactZoomPanPinchContext | null;
|
|
5
|
-
};
|
|
6
3
|
export declare const initialSetup: LibrarySetup;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { ReactZoomPanPinchContext } from "../../models";
|
|
2
|
+
export declare const handleDoubleClickStop: (contextInstance: ReactZoomPanPinchContext, event: MouseEvent | TouchEvent) => void;
|
|
3
|
+
export declare const handleDoubleClickResetMode: (contextInstance: ReactZoomPanPinchContext, event: MouseEvent | TouchEvent) => void;
|
|
2
4
|
export declare function handleDoubleClick(contextInstance: ReactZoomPanPinchContext, event: MouseEvent | TouchEvent): void;
|
|
3
5
|
export declare const isDoubleClickAllowed: (contextInstance: ReactZoomPanPinchContext, event: MouseEvent | TouchEvent) => boolean;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { ReactZoomPanPinchContext } from "../../models";
|
|
1
|
+
import { ReactZoomPanPinchContext, ReactZoomPanPinchState } from "../../models";
|
|
2
2
|
import { animations } from "../animations/animations.constants";
|
|
3
|
-
import { PositionType } from "../../models/calculations.model";
|
|
4
3
|
export declare const handleCalculateButtonZoom: (contextInstance: ReactZoomPanPinchContext, delta: number, step: number) => number;
|
|
5
4
|
export declare function handleZoomToViewCenter(contextInstance: ReactZoomPanPinchContext, delta: number, step: number, animationTime: number, animationType: keyof typeof animations): void;
|
|
6
|
-
export declare function resetTransformations(contextInstance: ReactZoomPanPinchContext, animationTime: number, animationType: keyof typeof animations): void;
|
|
7
|
-
export declare function getOffset(element: HTMLElement):
|
|
5
|
+
export declare function resetTransformations(contextInstance: ReactZoomPanPinchContext, animationTime: number, animationType: keyof typeof animations, onResetTransformation?: () => void): void;
|
|
6
|
+
export declare function getOffset(element: HTMLElement, wrapper: HTMLElement, content: HTMLElement, state: ReactZoomPanPinchState): {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
};
|
|
8
10
|
export declare function calculateZoomToNode(contextInstance: ReactZoomPanPinchContext, node: HTMLElement, customZoom?: number): {
|
|
9
11
|
positionX: number;
|
|
10
12
|
positionY: number;
|
|
11
13
|
scale: number;
|
|
12
14
|
};
|
|
13
|
-
export declare function isValidZoomNode(node: HTMLElement | null): boolean;
|
|
@@ -4,12 +4,12 @@ type StartCoordsType = {
|
|
|
4
4
|
y: number;
|
|
5
5
|
} | null;
|
|
6
6
|
export declare class ZoomPanPinch {
|
|
7
|
-
private onChange?;
|
|
8
7
|
props: ReactZoomPanPinchProps;
|
|
9
8
|
mounted: boolean;
|
|
10
9
|
transformState: ReactZoomPanPinchState;
|
|
11
10
|
setup: LibrarySetup;
|
|
12
11
|
observer?: ResizeObserver;
|
|
12
|
+
onChangeCallbacks: Set<(ctx: ReactZoomPanPinchRef) => void>;
|
|
13
13
|
wrapperComponent: HTMLDivElement | null;
|
|
14
14
|
contentComponent: HTMLDivElement | null;
|
|
15
15
|
isInitialized: boolean;
|
|
@@ -25,6 +25,7 @@ export declare class ZoomPanPinch {
|
|
|
25
25
|
pinchStartDistance: null | number;
|
|
26
26
|
pinchStartScale: null | number;
|
|
27
27
|
pinchMidpoint: null | PositionType;
|
|
28
|
+
doubleClickStopEventTimer: ReturnType<typeof setTimeout> | null;
|
|
28
29
|
velocity: VelocityType | null;
|
|
29
30
|
velocityTime: number | null;
|
|
30
31
|
lastMousePosition: PositionType | null;
|
|
@@ -34,7 +35,7 @@ export declare class ZoomPanPinch {
|
|
|
34
35
|
pressedKeys: {
|
|
35
36
|
[key: string]: boolean;
|
|
36
37
|
};
|
|
37
|
-
constructor(props: ReactZoomPanPinchProps
|
|
38
|
+
constructor(props: ReactZoomPanPinchProps);
|
|
38
39
|
mount: () => void;
|
|
39
40
|
unmount: () => void;
|
|
40
41
|
update: (newProps: ReactZoomPanPinchProps) => void;
|
|
@@ -61,6 +62,7 @@ export declare class ZoomPanPinch {
|
|
|
61
62
|
setCenter: () => void;
|
|
62
63
|
applyTransformation: () => void;
|
|
63
64
|
getContext: () => ReactZoomPanPinchRef;
|
|
65
|
+
onChange: (callback: (ref: ReactZoomPanPinchRef) => void) => () => void;
|
|
64
66
|
/**
|
|
65
67
|
* Initialization
|
|
66
68
|
*/
|
package/dist/index.cjs.js
CHANGED
|
@@ -8,42 +8,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
8
8
|
|
|
9
9
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
10
10
|
|
|
11
|
-
/******************************************************************************
|
|
12
|
-
Copyright (c) Microsoft Corporation.
|
|
13
|
-
|
|
14
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
15
|
-
purpose with or without fee is hereby granted.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
18
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
19
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
20
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
21
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
22
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
23
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
24
|
-
***************************************************************************** */
|
|
25
|
-
|
|
26
|
-
var __assign = function() {
|
|
27
|
-
__assign = Object.assign || function __assign(t) {
|
|
28
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
29
|
-
s = arguments[i];
|
|
30
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
31
|
-
}
|
|
32
|
-
return t;
|
|
33
|
-
};
|
|
34
|
-
return __assign.apply(this, arguments);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
function __spreadArray(to, from, pack) {
|
|
38
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
39
|
-
if (ar || !(i in from)) {
|
|
40
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
41
|
-
ar[i] = from[i];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
11
|
/**
|
|
48
12
|
* Rounds number to given decimal
|
|
49
13
|
* eg. roundNumber(2.34343, 1) => 2.3
|
|
@@ -630,16 +594,50 @@ function handleAlignToScaleBounds(contextInstance, mousePositionX, mousePosition
|
|
|
630
594
|
}
|
|
631
595
|
}
|
|
632
596
|
|
|
597
|
+
/******************************************************************************
|
|
598
|
+
Copyright (c) Microsoft Corporation.
|
|
599
|
+
|
|
600
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
601
|
+
purpose with or without fee is hereby granted.
|
|
602
|
+
|
|
603
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
604
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
605
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
606
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
607
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
608
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
609
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
610
|
+
***************************************************************************** */
|
|
611
|
+
|
|
612
|
+
var __assign = function() {
|
|
613
|
+
__assign = Object.assign || function __assign(t) {
|
|
614
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
615
|
+
s = arguments[i];
|
|
616
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
617
|
+
}
|
|
618
|
+
return t;
|
|
619
|
+
};
|
|
620
|
+
return __assign.apply(this, arguments);
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
function __spreadArray(to, from, pack) {
|
|
624
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
625
|
+
if (ar || !(i in from)) {
|
|
626
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
627
|
+
ar[i] = from[i];
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
631
|
+
}
|
|
632
|
+
|
|
633
633
|
var initialState = {
|
|
634
634
|
previousScale: 1,
|
|
635
635
|
scale: 1,
|
|
636
636
|
positionX: 0,
|
|
637
637
|
positionY: 0,
|
|
638
638
|
};
|
|
639
|
-
var contextInitialState = __assign(__assign({}, initialState), { setComponents: function () { return undefined; }, contextInstance: null });
|
|
640
639
|
var initialSetup = {
|
|
641
640
|
disabled: false,
|
|
642
|
-
performance: false,
|
|
643
641
|
minPositionX: null,
|
|
644
642
|
maxPositionX: null,
|
|
645
643
|
minPositionY: null,
|
|
@@ -762,7 +760,7 @@ function handleZoomToViewCenter(contextInstance, delta, step, animationTime, ani
|
|
|
762
760
|
}
|
|
763
761
|
animate(contextInstance, targetState, animationTime, animationType);
|
|
764
762
|
}
|
|
765
|
-
function resetTransformations(contextInstance, animationTime, animationType) {
|
|
763
|
+
function resetTransformations(contextInstance, animationTime, animationType, onResetTransformation) {
|
|
766
764
|
var setup = contextInstance.setup, wrapperComponent = contextInstance.wrapperComponent;
|
|
767
765
|
var limitToBounds = setup.limitToBounds;
|
|
768
766
|
var initialTransformation = createState(contextInstance.props);
|
|
@@ -781,33 +779,32 @@ function resetTransformations(contextInstance, animationTime, animationType) {
|
|
|
781
779
|
positionY === initialTransformation.positionY) {
|
|
782
780
|
return;
|
|
783
781
|
}
|
|
782
|
+
onResetTransformation === null || onResetTransformation === void 0 ? void 0 : onResetTransformation();
|
|
784
783
|
animate(contextInstance, newState, animationTime, animationType);
|
|
785
784
|
}
|
|
786
|
-
function getOffset(element) {
|
|
787
|
-
var
|
|
788
|
-
var
|
|
789
|
-
var
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
offsetTop += el.offsetTop;
|
|
793
|
-
el = el.offsetParent;
|
|
794
|
-
}
|
|
785
|
+
function getOffset(element, wrapper, content, state) {
|
|
786
|
+
var offset = element.getBoundingClientRect();
|
|
787
|
+
var wrapperOffset = wrapper.getBoundingClientRect();
|
|
788
|
+
var contentOffset = content.getBoundingClientRect();
|
|
789
|
+
var xOff = wrapperOffset.x * state.scale;
|
|
790
|
+
var yOff = wrapperOffset.y * state.scale;
|
|
795
791
|
return {
|
|
796
|
-
x:
|
|
797
|
-
y:
|
|
792
|
+
x: (offset.x - contentOffset.x + xOff) / state.scale,
|
|
793
|
+
y: (offset.y - contentOffset.y + yOff) / state.scale,
|
|
798
794
|
};
|
|
799
795
|
}
|
|
800
796
|
function calculateZoomToNode(contextInstance, node, customZoom) {
|
|
801
|
-
var wrapperComponent = contextInstance.wrapperComponent;
|
|
797
|
+
var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent, transformState = contextInstance.transformState;
|
|
802
798
|
var _a = contextInstance.setup, limitToBounds = _a.limitToBounds, minScale = _a.minScale, maxScale = _a.maxScale;
|
|
803
|
-
if (!wrapperComponent)
|
|
804
|
-
return
|
|
799
|
+
if (!wrapperComponent || !contentComponent)
|
|
800
|
+
return transformState;
|
|
805
801
|
var wrapperRect = wrapperComponent.getBoundingClientRect();
|
|
806
|
-
var nodeRect =
|
|
807
|
-
var
|
|
808
|
-
var
|
|
809
|
-
var
|
|
810
|
-
var
|
|
802
|
+
var nodeRect = node.getBoundingClientRect();
|
|
803
|
+
var nodeOffset = getOffset(node, wrapperComponent, contentComponent, transformState);
|
|
804
|
+
var nodeLeft = nodeOffset.x;
|
|
805
|
+
var nodeTop = nodeOffset.y;
|
|
806
|
+
var nodeWidth = nodeRect.width / transformState.scale;
|
|
807
|
+
var nodeHeight = nodeRect.height / transformState.scale;
|
|
811
808
|
var scaleX = wrapperComponent.offsetWidth / nodeWidth;
|
|
812
809
|
var scaleY = wrapperComponent.offsetHeight / nodeHeight;
|
|
813
810
|
var newScale = checkZoomBounds(customZoom || Math.min(scaleX, scaleY), minScale, maxScale, 0, false);
|
|
@@ -819,17 +816,6 @@ function calculateZoomToNode(contextInstance, node, customZoom) {
|
|
|
819
816
|
var _b = getMouseBoundedPosition(newPositionX, newPositionY, bounds, limitToBounds, 0, 0, wrapperComponent), x = _b.x, y = _b.y;
|
|
820
817
|
return { positionX: x, positionY: y, scale: newScale };
|
|
821
818
|
}
|
|
822
|
-
function isValidZoomNode(node) {
|
|
823
|
-
if (!node) {
|
|
824
|
-
console.error("Zoom node not found");
|
|
825
|
-
return false;
|
|
826
|
-
}
|
|
827
|
-
if ((node === null || node === void 0 ? void 0 : node.offsetWidth) === undefined || (node === null || node === void 0 ? void 0 : node.offsetHeight) === undefined) {
|
|
828
|
-
console.error("Zoom node is not valid - it must contain offsetWidth and offsetHeight");
|
|
829
|
-
return false;
|
|
830
|
-
}
|
|
831
|
-
return true;
|
|
832
|
-
}
|
|
833
819
|
|
|
834
820
|
var zoomIn = function (contextInstance) {
|
|
835
821
|
return function (step, animationTime, animationType) {
|
|
@@ -889,10 +875,7 @@ var zoomToElement = function (contextInstance) {
|
|
|
889
875
|
handleCancelAnimation(contextInstance);
|
|
890
876
|
var wrapperComponent = contextInstance.wrapperComponent;
|
|
891
877
|
var target = typeof node === "string" ? document.getElementById(node) : node;
|
|
892
|
-
if (wrapperComponent &&
|
|
893
|
-
isValidZoomNode(target) &&
|
|
894
|
-
target &&
|
|
895
|
-
wrapperComponent.contains(target)) {
|
|
878
|
+
if (wrapperComponent && target && wrapperComponent.contains(target)) {
|
|
896
879
|
var targetState = calculateZoomToNode(contextInstance, target, scale);
|
|
897
880
|
animate(contextInstance, targetState, animationTime, animationType);
|
|
898
881
|
}
|
|
@@ -1212,25 +1195,52 @@ var handlePinchStop = function (contextInstance) {
|
|
|
1212
1195
|
handleAlignToScaleBounds(contextInstance, pinchMidpoint === null || pinchMidpoint === void 0 ? void 0 : pinchMidpoint.x, pinchMidpoint === null || pinchMidpoint === void 0 ? void 0 : pinchMidpoint.y);
|
|
1213
1196
|
};
|
|
1214
1197
|
|
|
1198
|
+
var handleDoubleClickStop = function (contextInstance, event) {
|
|
1199
|
+
var onZoomStop = contextInstance.props.onZoomStop;
|
|
1200
|
+
var animationTime = contextInstance.setup.doubleClick.animationTime;
|
|
1201
|
+
cancelTimeout(contextInstance.doubleClickStopEventTimer);
|
|
1202
|
+
contextInstance.doubleClickStopEventTimer = setTimeout(function () {
|
|
1203
|
+
contextInstance.doubleClickStopEventTimer = null;
|
|
1204
|
+
handleCallback(getContext(contextInstance), event, onZoomStop);
|
|
1205
|
+
}, animationTime);
|
|
1206
|
+
};
|
|
1207
|
+
var handleDoubleClickResetMode = function (contextInstance, event) {
|
|
1208
|
+
var _a = contextInstance.props, onZoomStart = _a.onZoomStart, onZoom = _a.onZoom;
|
|
1209
|
+
var _b = contextInstance.setup.doubleClick, animationTime = _b.animationTime, animationType = _b.animationType;
|
|
1210
|
+
handleCallback(getContext(contextInstance), event, onZoomStart);
|
|
1211
|
+
resetTransformations(contextInstance, animationTime, animationType, function () {
|
|
1212
|
+
return handleCallback(getContext(contextInstance), event, onZoom);
|
|
1213
|
+
});
|
|
1214
|
+
handleDoubleClickStop(contextInstance, event);
|
|
1215
|
+
};
|
|
1215
1216
|
function handleDoubleClick(contextInstance, event) {
|
|
1216
|
-
var
|
|
1217
|
+
var setup = contextInstance.setup, doubleClickStopEventTimer = contextInstance.doubleClickStopEventTimer, transformState = contextInstance.transformState, contentComponent = contextInstance.contentComponent;
|
|
1218
|
+
var scale = transformState.scale;
|
|
1219
|
+
var _a = contextInstance.props, onZoomStart = _a.onZoomStart, onZoom = _a.onZoom;
|
|
1220
|
+
var _b = setup.doubleClick, disabled = _b.disabled, mode = _b.mode, step = _b.step, animationTime = _b.animationTime, animationType = _b.animationType;
|
|
1217
1221
|
if (disabled)
|
|
1218
1222
|
return;
|
|
1223
|
+
if (doubleClickStopEventTimer)
|
|
1224
|
+
return;
|
|
1219
1225
|
if (mode === "reset") {
|
|
1220
|
-
return
|
|
1226
|
+
return handleDoubleClickResetMode(contextInstance, event);
|
|
1221
1227
|
}
|
|
1222
|
-
var scale = contextInstance.transformState.scale;
|
|
1223
|
-
var contentComponent = contextInstance.contentComponent;
|
|
1224
1228
|
if (!contentComponent)
|
|
1225
1229
|
return console.error("No ContentComponent found");
|
|
1226
1230
|
var delta = mode === "zoomOut" ? -1 : 1;
|
|
1227
1231
|
var newScale = handleCalculateButtonZoom(contextInstance, delta, step);
|
|
1232
|
+
// stop execution when scale didn't change
|
|
1233
|
+
if (scale === newScale)
|
|
1234
|
+
return;
|
|
1235
|
+
handleCallback(getContext(contextInstance), event, onZoomStart);
|
|
1228
1236
|
var mousePosition = getMousePosition(event, contentComponent, scale);
|
|
1229
1237
|
var targetState = handleZoomToPoint(contextInstance, newScale, mousePosition.x, mousePosition.y);
|
|
1230
1238
|
if (!targetState) {
|
|
1231
1239
|
return console.error("Error during zoom event. New transformation state was not calculated.");
|
|
1232
1240
|
}
|
|
1241
|
+
handleCallback(getContext(contextInstance), event, onZoom);
|
|
1233
1242
|
animate(contextInstance, targetState, animationTime, animationType);
|
|
1243
|
+
handleDoubleClickStop(contextInstance, event);
|
|
1234
1244
|
}
|
|
1235
1245
|
var isDoubleClickAllowed = function (contextInstance, event) {
|
|
1236
1246
|
var isInitialized = contextInstance.isInitialized, setup = contextInstance.setup, wrapperComponent = contextInstance.wrapperComponent;
|
|
@@ -1243,16 +1253,14 @@ var isDoubleClickAllowed = function (contextInstance, event) {
|
|
|
1243
1253
|
var isExcluded = isExcludedNode(target, excluded);
|
|
1244
1254
|
if (isExcluded)
|
|
1245
1255
|
return false;
|
|
1246
|
-
if (!isAllowed)
|
|
1247
|
-
return false;
|
|
1248
1256
|
return true;
|
|
1249
1257
|
};
|
|
1250
1258
|
|
|
1251
1259
|
var ZoomPanPinch = /** @class */ (function () {
|
|
1252
|
-
function ZoomPanPinch(props
|
|
1260
|
+
function ZoomPanPinch(props) {
|
|
1253
1261
|
var _this = this;
|
|
1254
|
-
this.onChange = onChange;
|
|
1255
1262
|
this.mounted = true;
|
|
1263
|
+
this.onChangeCallbacks = new Set();
|
|
1256
1264
|
// Components
|
|
1257
1265
|
this.wrapperComponent = null;
|
|
1258
1266
|
this.contentComponent = null;
|
|
@@ -1273,6 +1281,8 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1273
1281
|
this.pinchStartDistance = null;
|
|
1274
1282
|
this.pinchStartScale = null;
|
|
1275
1283
|
this.pinchMidpoint = null;
|
|
1284
|
+
// double click helpers
|
|
1285
|
+
this.doubleClickStopEventTimer = null;
|
|
1276
1286
|
// velocity helpers
|
|
1277
1287
|
this.velocity = null;
|
|
1278
1288
|
this.velocityTime = null;
|
|
@@ -1529,7 +1539,6 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1529
1539
|
return Boolean(keys.find(function (key) { return _this.pressedKeys[key]; }));
|
|
1530
1540
|
};
|
|
1531
1541
|
this.setTransformState = function (scale, positionX, positionY) {
|
|
1532
|
-
var _a;
|
|
1533
1542
|
var onTransformed = _this.props.onTransformed;
|
|
1534
1543
|
if (!Number.isNaN(scale) &&
|
|
1535
1544
|
!Number.isNaN(positionX) &&
|
|
@@ -1540,9 +1549,9 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1540
1549
|
}
|
|
1541
1550
|
_this.transformState.positionX = positionX;
|
|
1542
1551
|
_this.transformState.positionY = positionY;
|
|
1543
|
-
var
|
|
1544
|
-
(
|
|
1545
|
-
handleCallback(
|
|
1552
|
+
var ctx_1 = getContext(_this);
|
|
1553
|
+
_this.onChangeCallbacks.forEach(function (callback) { return callback(ctx_1); });
|
|
1554
|
+
handleCallback(ctx_1, { scale: scale, positionX: positionX, positionY: positionY }, onTransformed);
|
|
1546
1555
|
_this.applyTransformation();
|
|
1547
1556
|
}
|
|
1548
1557
|
else {
|
|
@@ -1565,6 +1574,14 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1565
1574
|
this.getContext = function () {
|
|
1566
1575
|
return getContext(_this);
|
|
1567
1576
|
};
|
|
1577
|
+
this.onChange = function (callback) {
|
|
1578
|
+
if (!_this.onChangeCallbacks.has(callback)) {
|
|
1579
|
+
_this.onChangeCallbacks.add(callback);
|
|
1580
|
+
}
|
|
1581
|
+
return function () {
|
|
1582
|
+
_this.onChangeCallbacks.delete(callback);
|
|
1583
|
+
};
|
|
1584
|
+
};
|
|
1568
1585
|
/**
|
|
1569
1586
|
* Initialization
|
|
1570
1587
|
*/
|
|
@@ -1586,30 +1603,31 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1586
1603
|
return ZoomPanPinch;
|
|
1587
1604
|
}());
|
|
1588
1605
|
|
|
1589
|
-
var Context = React__default["default"].createContext(
|
|
1606
|
+
var Context = React__default["default"].createContext(null);
|
|
1607
|
+
var getContent = function (children, ctx) {
|
|
1608
|
+
if (typeof children === "function") {
|
|
1609
|
+
return children(ctx);
|
|
1610
|
+
}
|
|
1611
|
+
return children;
|
|
1612
|
+
};
|
|
1590
1613
|
var TransformWrapper = React__default["default"].forwardRef(function (props, ref) {
|
|
1591
1614
|
var _a = React.useState(0), forceUpdate = _a[1];
|
|
1592
|
-
var children = props.children
|
|
1593
|
-
var instance = React.useRef(new ZoomPanPinch(props
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
}
|
|
1597
|
-
})).current;
|
|
1598
|
-
var content = React.useMemo(function () {
|
|
1615
|
+
var children = props.children;
|
|
1616
|
+
var instance = React.useRef(new ZoomPanPinch(props)).current;
|
|
1617
|
+
var content = getContent(props.children, getContext(instance));
|
|
1618
|
+
var handleOnChange = React.useCallback(function () {
|
|
1599
1619
|
if (typeof children === "function") {
|
|
1600
|
-
|
|
1620
|
+
forceUpdate(function (prev) { return prev + 1; });
|
|
1601
1621
|
}
|
|
1602
|
-
|
|
1603
|
-
}, [children, instance]);
|
|
1604
|
-
var value = React.useMemo(function () {
|
|
1605
|
-
return __assign(__assign({}, instance.transformState), { setComponents: instance.init, contextInstance: instance });
|
|
1606
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1607
|
-
}, [JSON.stringify(instance.transformState)]);
|
|
1622
|
+
}, [children]);
|
|
1608
1623
|
React.useImperativeHandle(ref, function () { return getContext(instance); }, [instance]);
|
|
1609
1624
|
React.useEffect(function () {
|
|
1610
1625
|
instance.update(props);
|
|
1611
1626
|
}, [instance, props]);
|
|
1612
|
-
|
|
1627
|
+
React.useEffect(function () {
|
|
1628
|
+
return instance.onChange(handleOnChange);
|
|
1629
|
+
}, [instance, props, handleOnChange]);
|
|
1630
|
+
return React__default["default"].createElement(Context.Provider, { value: instance }, content);
|
|
1613
1631
|
});
|
|
1614
1632
|
|
|
1615
1633
|
function styleInject(css, ref) {
|
|
@@ -1645,14 +1663,14 @@ styleInject(css_248z);
|
|
|
1645
1663
|
|
|
1646
1664
|
var TransformComponent = function (_a) {
|
|
1647
1665
|
var children = _a.children, _b = _a.wrapperClass, wrapperClass = _b === void 0 ? "" : _b, _c = _a.contentClass, contentClass = _c === void 0 ? "" : _c, wrapperStyle = _a.wrapperStyle, contentStyle = _a.contentStyle, _d = _a.wrapperProps, wrapperProps = _d === void 0 ? {} : _d, _e = _a.contentProps, contentProps = _e === void 0 ? {} : _e;
|
|
1648
|
-
var
|
|
1666
|
+
var init = React.useContext(Context).init;
|
|
1649
1667
|
var wrapperRef = React.useRef(null);
|
|
1650
1668
|
var contentRef = React.useRef(null);
|
|
1651
1669
|
React.useEffect(function () {
|
|
1652
1670
|
var wrapper = wrapperRef.current;
|
|
1653
1671
|
var content = contentRef.current;
|
|
1654
|
-
if (wrapper !== null && content !== null &&
|
|
1655
|
-
|
|
1672
|
+
if (wrapper !== null && content !== null && init) {
|
|
1673
|
+
init(wrapper, content);
|
|
1656
1674
|
}
|
|
1657
1675
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1658
1676
|
}, []);
|
|
@@ -1662,10 +1680,16 @@ var TransformComponent = function (_a) {
|
|
|
1662
1680
|
|
|
1663
1681
|
var useTransformContext = function () {
|
|
1664
1682
|
var libraryContext = React.useContext(Context);
|
|
1665
|
-
|
|
1683
|
+
var _a = React.useState(getContext(libraryContext || {})), values = _a[0], setValues = _a[1];
|
|
1684
|
+
if (!libraryContext) {
|
|
1666
1685
|
throw new Error("Transform context mus be placed inside TransformWrapper");
|
|
1667
1686
|
}
|
|
1668
|
-
|
|
1687
|
+
React.useEffect(function () {
|
|
1688
|
+
libraryContext.onChange(function (ref) {
|
|
1689
|
+
setValues(ref);
|
|
1690
|
+
});
|
|
1691
|
+
}, [libraryContext]);
|
|
1692
|
+
return values;
|
|
1669
1693
|
};
|
|
1670
1694
|
|
|
1671
1695
|
exports.TransformComponent = TransformComponent;
|