react-zoom-pan-pinch 3.3.0 → 3.4.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 +38 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.esm.js +38 -2
- package/dist/index.esm.js.map +1 -1
- package/package.json +4 -1
- package/.eslintignore +0 -6
- package/.github/CODEOWNERS +0 -36
- package/.github/FUNDING.yml +0 -13
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/workflows/docs.yml +0 -34
- package/.github/workflows/release.yml +0 -46
- package/.github/workflows/tests.yml +0 -42
- package/.prettierrc +0 -10
- package/.releaserc.json +0 -63
- package/.storybook/main.js +0 -23
- package/.storybook/preview-head.html +0 -5
- package/.storybook/preview.js +0 -11
- package/.storybook/theme-overrides.css +0 -49
- package/CHANGELOG.md +0 -26
- package/Code_of_Conduct.md +0 -61
- package/Contributing.md +0 -236
- package/__tests__/features/props.spec.tsx +0 -11
- package/__tests__/features/rendering.spec.tsx +0 -36
- package/__tests__/shared/render.shared.tsx +0 -41
- package/__tests__/utils/controls.utils.tsx +0 -25
- package/__tests__/utils/example.tsx +0 -81
- package/commitlint.config.js +0 -1
- package/dist/__tests__/features/props.spec.d.ts +0 -1
- package/dist/__tests__/features/rendering.spec.d.ts +0 -1
- package/dist/__tests__/shared/render.shared.d.ts +0 -11
- package/dist/__tests__/utils/controls.utils.d.ts +0 -3
- package/dist/__tests__/utils/example.d.ts +0 -6
- package/dist/src/components/index.d.ts +0 -4
- package/dist/src/components/keep-scale/keep-scale.d.ts +0 -2
- package/dist/src/components/mini-map/mini-map.d.ts +0 -8
- package/dist/src/components/mini-map/use-resize.hook.d.ts +0 -8
- package/dist/src/components/transform-component/transform-component.d.ts +0 -12
- package/dist/src/components/transform-wrapper/transform-wrapper.d.ts +0 -5
- package/dist/src/constants/state.constants.d.ts +0 -3
- package/dist/src/core/animations/animations.constants.d.ts +0 -16
- package/dist/src/core/animations/animations.utils.d.ts +0 -4
- package/dist/src/core/bounds/bounds.types.d.ts +0 -8
- package/dist/src/core/bounds/bounds.utils.d.ts +0 -17
- package/dist/src/core/double-click/double-click.logic.d.ts +0 -5
- package/dist/src/core/handlers/handlers.logic.d.ts +0 -8
- package/dist/src/core/handlers/handlers.utils.d.ts +0 -14
- package/dist/src/core/instance.core.d.ts +0 -77
- package/dist/src/core/pan/panning.logic.d.ts +0 -5
- package/dist/src/core/pan/panning.utils.d.ts +0 -10
- package/dist/src/core/pan/velocity.logic.d.ts +0 -5
- package/dist/src/core/pan/velocity.utils.d.ts +0 -5
- package/dist/src/core/pinch/pinch.logic.d.ts +0 -4
- package/dist/src/core/pinch/pinch.utils.d.ts +0 -6
- package/dist/src/core/wheel/wheel.logic.d.ts +0 -4
- package/dist/src/core/wheel/wheel.utils.d.ts +0 -7
- package/dist/src/core/zoom/zoom.logic.d.ts +0 -3
- package/dist/src/core/zoom/zoom.utils.d.ts +0 -3
- package/dist/src/hooks/index.d.ts +0 -4
- package/dist/src/hooks/use-controls.d.ts +0 -2
- package/dist/src/hooks/use-transform-context.d.ts +0 -1
- package/dist/src/hooks/use-transform-effect.d.ts +0 -2
- package/dist/src/hooks/use-transform-init.d.ts +0 -2
- package/dist/src/index.d.ts +0 -5
- package/dist/src/models/calculations.model.d.ts +0 -25
- package/dist/src/models/context.model.d.ts +0 -127
- package/dist/src/models/helpers.model.d.ts +0 -5
- package/dist/src/models/index.d.ts +0 -3
- package/dist/src/stories/docs/handlers.d.ts +0 -12
- package/dist/src/stories/docs/props.d.ts +0 -14
- package/dist/src/stories/examples/content-rerendering/example.d.ts +0 -2
- package/dist/src/stories/examples/image-responsive/example.d.ts +0 -2
- package/dist/src/stories/examples/keep-scale/example.d.ts +0 -2
- package/dist/src/stories/examples/mini-map/example.d.ts +0 -1
- package/dist/src/stories/examples/stress/example.d.ts +0 -2
- package/dist/src/stories/examples/svg-zoom-to-element/example.d.ts +0 -2
- package/dist/src/stories/examples/zoom-to-element/example.d.ts +0 -2
- package/dist/src/stories/types/args.types.d.ts +0 -280
- package/dist/src/stories/utils/args.utils.d.ts +0 -3
- package/dist/src/stories/utils/code.utils.d.ts +0 -6
- package/dist/src/stories/utils/controls.utils.d.ts +0 -3
- package/dist/src/stories/utils/index.d.ts +0 -3
- package/dist/src/utils/calculations.utils.d.ts +0 -11
- package/dist/src/utils/callback.utils.d.ts +0 -2
- package/dist/src/utils/context.utils.d.ts +0 -4
- package/dist/src/utils/event.utils.d.ts +0 -1
- package/dist/src/utils/helpers.utils.d.ts +0 -2
- package/dist/src/utils/index.d.ts +0 -8
- package/dist/src/utils/ref.utils.d.ts +0 -2
- package/dist/src/utils/state.utils.d.ts +0 -3
- package/dist/src/utils/styles.utils.d.ts +0 -4
- package/jest.config.ts +0 -45
- package/rollup.config.js +0 -51
- package/src/.eslintrc.json +0 -90
- package/src/components/index.ts +0 -4
- package/src/components/keep-scale/keep-scale.tsx +0 -28
- package/src/components/mini-map/mini-map.tsx +0 -188
- package/src/components/mini-map/use-resize.hook.ts +0 -69
- package/src/components/transform-component/transform-component.module.css +0 -30
- package/src/components/transform-component/transform-component.tsx +0 -61
- package/src/components/transform-wrapper/transform-wrapper.tsx +0 -39
- package/src/constants/state.constants.ts +0 -77
- package/src/core/animations/animations.constants.ts +0 -78
- package/src/core/animations/animations.utils.ts +0 -114
- package/src/core/bounds/bounds.types.ts +0 -8
- package/src/core/bounds/bounds.utils.ts +0 -187
- package/src/core/double-click/double-click.logic.ts +0 -116
- package/src/core/handlers/handlers.logic.ts +0 -115
- package/src/core/handlers/handlers.utils.ts +0 -195
- package/src/core/instance.core.ts +0 -503
- package/src/core/pan/panning.logic.ts +0 -100
- package/src/core/pan/panning.utils.ts +0 -196
- package/src/core/pan/velocity.logic.ts +0 -149
- package/src/core/pan/velocity.utils.ts +0 -79
- package/src/core/pinch/pinch.logic.ts +0 -81
- package/src/core/pinch/pinch.utils.ts +0 -88
- package/src/core/wheel/wheel.logic.ts +0 -121
- package/src/core/wheel/wheel.utils.ts +0 -122
- package/src/core/zoom/zoom.logic.ts +0 -69
- package/src/core/zoom/zoom.utils.ts +0 -58
- package/src/hooks/index.ts +0 -4
- package/src/hooks/use-controls.tsx +0 -9
- package/src/hooks/use-transform-context.tsx +0 -13
- package/src/hooks/use-transform-effect.tsx +0 -22
- package/src/hooks/use-transform-init.tsx +0 -27
- package/src/index.ts +0 -6
- package/src/models/calculations.model.ts +0 -26
- package/src/models/context.model.ts +0 -199
- package/src/models/helpers.model.ts +0 -15
- package/src/models/index.ts +0 -3
- package/src/react-app-env.d.ts +0 -1
- package/src/stories/assets/big-image.jpeg +0 -0
- package/src/stories/assets/map.jpg +0 -0
- package/src/stories/assets/medium-image.jpg +0 -0
- package/src/stories/assets/pin.svg +0 -1
- package/src/stories/assets/small-image.jpg +0 -0
- package/src/stories/assets/svg-example.svg +0 -14
- package/src/stories/docs/Introduction.stories.mdx +0 -174
- package/src/stories/docs/handlers.stories.mdx +0 -48
- package/src/stories/docs/handlers.tsx +0 -107
- package/src/stories/docs/props.stories.mdx +0 -92
- package/src/stories/docs/props.tsx +0 -526
- package/src/stories/examples/content/content.stories.mdx +0 -121
- package/src/stories/examples/content-rerendering/content-updating.stories.mdx +0 -45
- package/src/stories/examples/content-rerendering/example.tsx +0 -73
- package/src/stories/examples/controls/controls.stories.mdx +0 -71
- package/src/stories/examples/image-big/image-big.stories.mdx +0 -43
- package/src/stories/examples/image-medium/image-medium.stories.mdx +0 -41
- package/src/stories/examples/image-responsive/example.tsx +0 -103
- package/src/stories/examples/image-responsive/image-responsive.stories.mdx +0 -32
- package/src/stories/examples/image-small/image-small.stories.mdx +0 -41
- package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +0 -46
- package/src/stories/examples/keep-scale/example.tsx +0 -92
- package/src/stories/examples/keep-scale/keep-scale.stories.mdx +0 -45
- package/src/stories/examples/mini-map/example.tsx +0 -54
- package/src/stories/examples/mini-map/mini-map.stories.mdx +0 -33
- package/src/stories/examples/stress/example.tsx +0 -23
- package/src/stories/examples/stress/stress-test.stories.mdx +0 -28
- package/src/stories/examples/svg-zoom-to-element/creativity.svg +0 -143
- package/src/stories/examples/svg-zoom-to-element/example.tsx +0 -57
- package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +0 -28
- package/src/stories/examples/zoom-to-element/example.tsx +0 -94
- package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +0 -28
- package/src/stories/hooks/use-controls.stories.mdx +0 -24
- package/src/stories/hooks/use-transform-context.stories.mdx +0 -15
- package/src/stories/hooks/use-transform-effect.stories.mdx +0 -29
- package/src/stories/hooks/use-transform-init.stories.mdx +0 -25
- package/src/stories/types/args.types.ts +0 -211
- package/src/stories/utils/args.utils.ts +0 -34
- package/src/stories/utils/code.utils.tsx +0 -24
- package/src/stories/utils/controls.utils.tsx +0 -43
- package/src/stories/utils/index.ts +0 -3
- package/src/stories/utils/styles.module.css +0 -34
- package/src/styles.css +0 -8
- package/src/typings.d.ts +0 -10
- package/src/utils/calculations.utils.ts +0 -16
- package/src/utils/callback.utils.ts +0 -11
- package/src/utils/context.utils.ts +0 -48
- package/src/utils/event.utils.ts +0 -22
- package/src/utils/helpers.utils.ts +0 -27
- package/src/utils/index.ts +0 -8
- package/src/utils/ref.utils.ts +0 -16
- package/src/utils/state.utils.ts +0 -40
- package/src/utils/styles.utils.ts +0 -44
- package/tsconfig.json +0 -33
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */
|
|
2
|
-
import { ReactZoomPanPinchContext } from "../../models";
|
|
3
|
-
import { handleCallback } from "../../utils/callback.utils";
|
|
4
|
-
import { getContext } from "../../utils/context.utils";
|
|
5
|
-
import { cancelTimeout } from "../../utils/helpers.utils";
|
|
6
|
-
import { handleCancelAnimation } from "../animations/animations.utils";
|
|
7
|
-
import { handleCalculateBounds } from "../bounds/bounds.utils";
|
|
8
|
-
import {
|
|
9
|
-
getDelta,
|
|
10
|
-
handleCalculateWheelZoom,
|
|
11
|
-
handleWheelZoomStop,
|
|
12
|
-
getMousePosition,
|
|
13
|
-
} from "./wheel.utils";
|
|
14
|
-
import { handleAlignToScaleBounds } from "../zoom/zoom.logic";
|
|
15
|
-
import { handleCalculateZoomPositions } from "../zoom/zoom.utils";
|
|
16
|
-
|
|
17
|
-
const wheelStopEventTime = 160;
|
|
18
|
-
const wheelAnimationTime = 100;
|
|
19
|
-
|
|
20
|
-
export const handleWheelStart = (
|
|
21
|
-
contextInstance: ReactZoomPanPinchContext,
|
|
22
|
-
event: WheelEvent,
|
|
23
|
-
): void => {
|
|
24
|
-
const { onWheelStart, onZoomStart } = contextInstance.props;
|
|
25
|
-
|
|
26
|
-
if (!contextInstance.wheelStopEventTimer) {
|
|
27
|
-
handleCancelAnimation(contextInstance);
|
|
28
|
-
handleCallback(getContext(contextInstance), event, onWheelStart);
|
|
29
|
-
handleCallback(getContext(contextInstance), event, onZoomStart);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const handleWheelZoom = (
|
|
34
|
-
contextInstance: ReactZoomPanPinchContext,
|
|
35
|
-
event: WheelEvent,
|
|
36
|
-
): void => {
|
|
37
|
-
const { onWheel, onZoom } = contextInstance.props;
|
|
38
|
-
|
|
39
|
-
const { contentComponent, setup, transformState } = contextInstance;
|
|
40
|
-
const { scale } = transformState;
|
|
41
|
-
const {
|
|
42
|
-
limitToBounds,
|
|
43
|
-
centerZoomedOut,
|
|
44
|
-
zoomAnimation,
|
|
45
|
-
wheel,
|
|
46
|
-
disablePadding,
|
|
47
|
-
smooth,
|
|
48
|
-
} = setup;
|
|
49
|
-
const { size, disabled } = zoomAnimation;
|
|
50
|
-
const { step, smoothStep } = wheel;
|
|
51
|
-
|
|
52
|
-
if (!contentComponent) {
|
|
53
|
-
throw new Error("Component not mounted");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
event.preventDefault();
|
|
57
|
-
event.stopPropagation();
|
|
58
|
-
|
|
59
|
-
const delta = getDelta(event, null);
|
|
60
|
-
const zoomStep = smooth ? smoothStep * Math.abs(event.deltaY) : step;
|
|
61
|
-
const newScale = handleCalculateWheelZoom(
|
|
62
|
-
contextInstance,
|
|
63
|
-
delta,
|
|
64
|
-
zoomStep,
|
|
65
|
-
!event.ctrlKey,
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
// if scale not change
|
|
69
|
-
if (scale === newScale) return;
|
|
70
|
-
|
|
71
|
-
const bounds = handleCalculateBounds(contextInstance, newScale);
|
|
72
|
-
|
|
73
|
-
const mousePosition = getMousePosition(event, contentComponent, scale);
|
|
74
|
-
|
|
75
|
-
const isPaddingDisabled =
|
|
76
|
-
disabled || size === 0 || centerZoomedOut || disablePadding;
|
|
77
|
-
const isLimitedToBounds = limitToBounds && isPaddingDisabled;
|
|
78
|
-
|
|
79
|
-
const { x, y } = handleCalculateZoomPositions(
|
|
80
|
-
contextInstance,
|
|
81
|
-
mousePosition.x,
|
|
82
|
-
mousePosition.y,
|
|
83
|
-
newScale,
|
|
84
|
-
bounds,
|
|
85
|
-
isLimitedToBounds,
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
contextInstance.previousWheelEvent = event;
|
|
89
|
-
|
|
90
|
-
contextInstance.setTransformState(newScale, x, y);
|
|
91
|
-
|
|
92
|
-
handleCallback(getContext(contextInstance), event, onWheel);
|
|
93
|
-
handleCallback(getContext(contextInstance), event, onZoom);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export const handleWheelStop = (
|
|
97
|
-
contextInstance: ReactZoomPanPinchContext,
|
|
98
|
-
event: WheelEvent,
|
|
99
|
-
): void => {
|
|
100
|
-
const { onWheelStop, onZoomStop } = contextInstance.props;
|
|
101
|
-
|
|
102
|
-
// fire animation
|
|
103
|
-
cancelTimeout(contextInstance.wheelAnimationTimer);
|
|
104
|
-
contextInstance.wheelAnimationTimer = setTimeout(() => {
|
|
105
|
-
if (!contextInstance.mounted) return;
|
|
106
|
-
handleAlignToScaleBounds(contextInstance, event.x, event.y);
|
|
107
|
-
contextInstance.wheelAnimationTimer = null;
|
|
108
|
-
}, wheelAnimationTime);
|
|
109
|
-
|
|
110
|
-
// Wheel stop event
|
|
111
|
-
const hasStoppedZooming = handleWheelZoomStop(contextInstance, event);
|
|
112
|
-
if (hasStoppedZooming) {
|
|
113
|
-
cancelTimeout(contextInstance.wheelStopEventTimer);
|
|
114
|
-
contextInstance.wheelStopEventTimer = setTimeout(() => {
|
|
115
|
-
if (!contextInstance.mounted) return;
|
|
116
|
-
contextInstance.wheelStopEventTimer = null;
|
|
117
|
-
handleCallback(getContext(contextInstance), event, onWheelStop);
|
|
118
|
-
handleCallback(getContext(contextInstance), event, onZoomStop);
|
|
119
|
-
}, wheelStopEventTime);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { ReactZoomPanPinchContext, PositionType } from "../../models";
|
|
2
|
-
import { checkIsNumber, isExcludedNode, roundNumber } from "../../utils";
|
|
3
|
-
import { checkZoomBounds } from "../zoom/zoom.utils";
|
|
4
|
-
|
|
5
|
-
export const isWheelAllowed = (
|
|
6
|
-
contextInstance: ReactZoomPanPinchContext,
|
|
7
|
-
event: WheelEvent,
|
|
8
|
-
): boolean => {
|
|
9
|
-
const { disabled, wheelDisabled, touchPadDisabled, excluded } =
|
|
10
|
-
contextInstance.setup.wheel;
|
|
11
|
-
const { isInitialized, isPanning } = contextInstance;
|
|
12
|
-
|
|
13
|
-
const target = event.target as HTMLElement;
|
|
14
|
-
const isAllowed = isInitialized && !isPanning && !disabled && target;
|
|
15
|
-
|
|
16
|
-
if (!isAllowed) return false;
|
|
17
|
-
// Event ctrlKey detects if touchpad action is executing wheel or pinch gesture
|
|
18
|
-
if (wheelDisabled && !event.ctrlKey) return false;
|
|
19
|
-
if (touchPadDisabled && event.ctrlKey) return false;
|
|
20
|
-
|
|
21
|
-
const isExcluded = isExcludedNode(target, excluded);
|
|
22
|
-
|
|
23
|
-
if (isExcluded) return false;
|
|
24
|
-
|
|
25
|
-
return true;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const getDeltaY = (event?: WheelEvent) => {
|
|
29
|
-
if (event) {
|
|
30
|
-
return event.deltaY < 0 ? 1 : -1;
|
|
31
|
-
}
|
|
32
|
-
return 0;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export function getDelta(
|
|
36
|
-
event: WheelEvent,
|
|
37
|
-
customDelta?: number | null,
|
|
38
|
-
): number {
|
|
39
|
-
const deltaY = getDeltaY(event);
|
|
40
|
-
const delta = checkIsNumber(customDelta, deltaY);
|
|
41
|
-
return delta;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function getMousePosition(
|
|
45
|
-
event: WheelEvent | MouseEvent | TouchEvent,
|
|
46
|
-
contentComponent: HTMLDivElement,
|
|
47
|
-
scale: number,
|
|
48
|
-
): PositionType {
|
|
49
|
-
const contentRect = contentComponent.getBoundingClientRect();
|
|
50
|
-
|
|
51
|
-
let mouseX = 0;
|
|
52
|
-
let mouseY = 0;
|
|
53
|
-
|
|
54
|
-
if ("clientX" in event) {
|
|
55
|
-
// mouse position x, y over wrapper component
|
|
56
|
-
mouseX = (event.clientX - contentRect.left) / scale;
|
|
57
|
-
mouseY = (event.clientY - contentRect.top) / scale;
|
|
58
|
-
} else {
|
|
59
|
-
const touch = event.touches[0];
|
|
60
|
-
mouseX = (touch.clientX - contentRect.left) / scale;
|
|
61
|
-
mouseY = (touch.clientY - contentRect.top) / scale;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (Number.isNaN(mouseX) || Number.isNaN(mouseY))
|
|
65
|
-
console.error("No mouse or touch offset found");
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
x: mouseX,
|
|
69
|
-
y: mouseY,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export const handleCalculateWheelZoom = (
|
|
74
|
-
contextInstance: ReactZoomPanPinchContext,
|
|
75
|
-
delta: number,
|
|
76
|
-
step: number,
|
|
77
|
-
disable: boolean,
|
|
78
|
-
getTarget?: boolean,
|
|
79
|
-
): number => {
|
|
80
|
-
const { scale } = contextInstance.transformState;
|
|
81
|
-
const { wrapperComponent, setup } = contextInstance;
|
|
82
|
-
const { maxScale, minScale, zoomAnimation, disablePadding } = setup;
|
|
83
|
-
const { size, disabled } = zoomAnimation;
|
|
84
|
-
|
|
85
|
-
if (!wrapperComponent) {
|
|
86
|
-
throw new Error("Wrapper is not mounted");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const targetScale = scale + delta * step;
|
|
90
|
-
|
|
91
|
-
if (getTarget) return targetScale;
|
|
92
|
-
const paddingEnabled = disable ? false : !disabled;
|
|
93
|
-
const newScale = checkZoomBounds(
|
|
94
|
-
roundNumber(targetScale, 3),
|
|
95
|
-
minScale,
|
|
96
|
-
maxScale,
|
|
97
|
-
size,
|
|
98
|
-
paddingEnabled && !disablePadding,
|
|
99
|
-
);
|
|
100
|
-
return newScale;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export const handleWheelZoomStop = (
|
|
104
|
-
contextInstance: ReactZoomPanPinchContext,
|
|
105
|
-
event: WheelEvent,
|
|
106
|
-
): boolean => {
|
|
107
|
-
const { previousWheelEvent } = contextInstance;
|
|
108
|
-
const { scale } = contextInstance.transformState;
|
|
109
|
-
const { maxScale, minScale } = contextInstance.setup;
|
|
110
|
-
|
|
111
|
-
if (!previousWheelEvent) return false;
|
|
112
|
-
if (scale < maxScale || scale > minScale) return true;
|
|
113
|
-
if (Math.sign(previousWheelEvent.deltaY) !== Math.sign(event.deltaY))
|
|
114
|
-
return true;
|
|
115
|
-
if (previousWheelEvent.deltaY > 0 && previousWheelEvent.deltaY < event.deltaY)
|
|
116
|
-
return true;
|
|
117
|
-
if (previousWheelEvent.deltaY < 0 && previousWheelEvent.deltaY > event.deltaY)
|
|
118
|
-
return true;
|
|
119
|
-
if (Math.sign(previousWheelEvent.deltaY) !== Math.sign(event.deltaY))
|
|
120
|
-
return true;
|
|
121
|
-
return false;
|
|
122
|
-
};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { ReactZoomPanPinchContext, ReactZoomPanPinchState } from "../../models";
|
|
2
|
-
import { roundNumber } from "../../utils";
|
|
3
|
-
import { animate } from "../animations/animations.utils";
|
|
4
|
-
import { handleCalculateBounds } from "../bounds/bounds.utils";
|
|
5
|
-
import { handleAlignToBounds } from "../pan/panning.logic";
|
|
6
|
-
import { checkZoomBounds, handleCalculateZoomPositions } from "./zoom.utils";
|
|
7
|
-
|
|
8
|
-
export function handleZoomToPoint(
|
|
9
|
-
contextInstance: ReactZoomPanPinchContext,
|
|
10
|
-
scale: number,
|
|
11
|
-
mouseX: number,
|
|
12
|
-
mouseY: number,
|
|
13
|
-
): Omit<ReactZoomPanPinchState, "previousScale"> | undefined {
|
|
14
|
-
const { minScale, maxScale, limitToBounds } = contextInstance.setup;
|
|
15
|
-
|
|
16
|
-
const newScale = checkZoomBounds(
|
|
17
|
-
roundNumber(scale, 2),
|
|
18
|
-
minScale,
|
|
19
|
-
maxScale,
|
|
20
|
-
0,
|
|
21
|
-
false,
|
|
22
|
-
);
|
|
23
|
-
const bounds = handleCalculateBounds(contextInstance, newScale);
|
|
24
|
-
|
|
25
|
-
const { x, y } = handleCalculateZoomPositions(
|
|
26
|
-
contextInstance,
|
|
27
|
-
mouseX,
|
|
28
|
-
mouseY,
|
|
29
|
-
newScale,
|
|
30
|
-
bounds,
|
|
31
|
-
limitToBounds,
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
return { scale: newScale, positionX: x, positionY: y };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function handleAlignToScaleBounds(
|
|
38
|
-
contextInstance: ReactZoomPanPinchContext,
|
|
39
|
-
mousePositionX?: number,
|
|
40
|
-
mousePositionY?: number,
|
|
41
|
-
): void {
|
|
42
|
-
const { scale } = contextInstance.transformState;
|
|
43
|
-
const { wrapperComponent } = contextInstance;
|
|
44
|
-
const { minScale, limitToBounds, zoomAnimation } = contextInstance.setup;
|
|
45
|
-
const { disabled, animationTime, animationType } = zoomAnimation;
|
|
46
|
-
|
|
47
|
-
const isDisabled = disabled || scale >= minScale;
|
|
48
|
-
|
|
49
|
-
if (scale >= 1 || limitToBounds) {
|
|
50
|
-
// fire fit to bounds animation
|
|
51
|
-
handleAlignToBounds(contextInstance);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (isDisabled || !wrapperComponent || !contextInstance.mounted) return;
|
|
55
|
-
|
|
56
|
-
const mouseX = mousePositionX || wrapperComponent.offsetWidth / 2;
|
|
57
|
-
const mouseY = mousePositionY || wrapperComponent.offsetHeight / 2;
|
|
58
|
-
|
|
59
|
-
const targetState = handleZoomToPoint(
|
|
60
|
-
contextInstance,
|
|
61
|
-
minScale,
|
|
62
|
-
mouseX,
|
|
63
|
-
mouseY,
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
if (targetState) {
|
|
67
|
-
animate(contextInstance, targetState, animationTime, animationType);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BoundsType,
|
|
3
|
-
PositionType,
|
|
4
|
-
ReactZoomPanPinchContext,
|
|
5
|
-
} from "../../models";
|
|
6
|
-
import { getMouseBoundedPosition } from "../bounds/bounds.utils";
|
|
7
|
-
|
|
8
|
-
export function handleCalculateZoomPositions(
|
|
9
|
-
contextInstance: ReactZoomPanPinchContext,
|
|
10
|
-
mouseX: number,
|
|
11
|
-
mouseY: number,
|
|
12
|
-
newScale: number,
|
|
13
|
-
bounds: BoundsType,
|
|
14
|
-
limitToBounds: boolean,
|
|
15
|
-
): PositionType {
|
|
16
|
-
const { scale, positionX, positionY } = contextInstance.transformState;
|
|
17
|
-
|
|
18
|
-
const scaleDifference = newScale - scale;
|
|
19
|
-
|
|
20
|
-
if (typeof mouseX !== "number" || typeof mouseY !== "number") {
|
|
21
|
-
console.error("Mouse X and Y position were not provided!");
|
|
22
|
-
return { x: positionX, y: positionY };
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const calculatedPositionX = positionX - mouseX * scaleDifference;
|
|
26
|
-
const calculatedPositionY = positionY - mouseY * scaleDifference;
|
|
27
|
-
|
|
28
|
-
// do not limit to bounds when there is padding animation,
|
|
29
|
-
// it causes animation strange behaviour
|
|
30
|
-
|
|
31
|
-
const newPositions = getMouseBoundedPosition(
|
|
32
|
-
calculatedPositionX,
|
|
33
|
-
calculatedPositionY,
|
|
34
|
-
bounds,
|
|
35
|
-
limitToBounds,
|
|
36
|
-
0,
|
|
37
|
-
0,
|
|
38
|
-
null,
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
return newPositions;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function checkZoomBounds(
|
|
45
|
-
zoom: number,
|
|
46
|
-
minScale: number,
|
|
47
|
-
maxScale: number,
|
|
48
|
-
zoomPadding: number,
|
|
49
|
-
enablePadding: boolean,
|
|
50
|
-
): number {
|
|
51
|
-
const scalePadding = enablePadding ? zoomPadding : 0;
|
|
52
|
-
const minScaleWithPadding = minScale - scalePadding;
|
|
53
|
-
|
|
54
|
-
if (!Number.isNaN(maxScale) && zoom >= maxScale) return maxScale;
|
|
55
|
-
if (!Number.isNaN(minScale) && zoom <= minScaleWithPadding)
|
|
56
|
-
return minScaleWithPadding;
|
|
57
|
-
return zoom;
|
|
58
|
-
}
|
package/src/hooks/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ReactZoomPanPinchContentRef } from "models";
|
|
2
|
-
import { getControls } from "utils";
|
|
3
|
-
import { useTransformContext } from "./use-transform-context";
|
|
4
|
-
|
|
5
|
-
export const useControls = (): ReactZoomPanPinchContentRef => {
|
|
6
|
-
const libraryContext = useTransformContext();
|
|
7
|
-
|
|
8
|
-
return getControls(libraryContext);
|
|
9
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
|
|
3
|
-
import { Context } from "components";
|
|
4
|
-
|
|
5
|
-
export const useTransformContext = () => {
|
|
6
|
-
const libraryContext = useContext(Context);
|
|
7
|
-
|
|
8
|
-
if (!libraryContext) {
|
|
9
|
-
throw new Error("Transform context must be placed inside TransformWrapper");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return libraryContext;
|
|
13
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
import { getState } from "utils";
|
|
4
|
-
import { ReactZoomPanPinchContextState } from "../models";
|
|
5
|
-
import { useTransformContext } from "./use-transform-context";
|
|
6
|
-
|
|
7
|
-
export const useTransformEffect = (
|
|
8
|
-
callback: (ref: ReactZoomPanPinchContextState) => void | (() => void),
|
|
9
|
-
): void => {
|
|
10
|
-
const libraryContext = useTransformContext();
|
|
11
|
-
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
let unmountCallback: void | (() => void);
|
|
14
|
-
const unmount = libraryContext.onChange((ref) => {
|
|
15
|
-
unmountCallback = callback(getState(ref.instance));
|
|
16
|
-
});
|
|
17
|
-
return () => {
|
|
18
|
-
unmount();
|
|
19
|
-
unmountCallback?.();
|
|
20
|
-
};
|
|
21
|
-
}, [callback, libraryContext]);
|
|
22
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
import { getState } from "utils";
|
|
4
|
-
import { ReactZoomPanPinchContextState } from "../models";
|
|
5
|
-
import { useTransformContext } from "./use-transform-context";
|
|
6
|
-
|
|
7
|
-
export const useTransformInit = (
|
|
8
|
-
callback: (ref: ReactZoomPanPinchContextState) => void | (() => void),
|
|
9
|
-
): void => {
|
|
10
|
-
const libraryContext = useTransformContext();
|
|
11
|
-
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
let unmountCallback: void | (() => void);
|
|
14
|
-
let unmount: void | (() => void);
|
|
15
|
-
if (libraryContext.contentComponent && libraryContext.wrapperComponent) {
|
|
16
|
-
unmountCallback = callback(getState(libraryContext));
|
|
17
|
-
} else {
|
|
18
|
-
unmount = libraryContext.onInit((ref) => {
|
|
19
|
-
unmountCallback = callback(getState(ref.instance));
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return () => {
|
|
23
|
-
unmount?.();
|
|
24
|
-
unmountCallback?.();
|
|
25
|
-
};
|
|
26
|
-
}, []);
|
|
27
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export type SizeType = {
|
|
2
|
-
width: number;
|
|
3
|
-
height: number;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export type PositionType = {
|
|
7
|
-
x: number;
|
|
8
|
-
y: number;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type StateType = { scale: number; positionX: number; positionY: number };
|
|
12
|
-
|
|
13
|
-
export type VelocityType = {
|
|
14
|
-
velocityX: number;
|
|
15
|
-
velocityY: number;
|
|
16
|
-
total: number;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type BoundsType = {
|
|
20
|
-
minPositionX: number;
|
|
21
|
-
maxPositionX: number;
|
|
22
|
-
minPositionY: number;
|
|
23
|
-
maxPositionY: number;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type AnimationType = () => void | number;
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
import { animations } from "../core/animations/animations.constants";
|
|
4
|
-
import { DeepNonNullable } from "./helpers.model";
|
|
5
|
-
import {
|
|
6
|
-
zoomIn,
|
|
7
|
-
zoomToElement,
|
|
8
|
-
centerView,
|
|
9
|
-
resetTransform,
|
|
10
|
-
setTransform,
|
|
11
|
-
zoomOut,
|
|
12
|
-
} from "../core/handlers/handlers.logic";
|
|
13
|
-
import { ZoomPanPinch } from "../core/instance.core";
|
|
14
|
-
|
|
15
|
-
export type ReactZoomPanPinchContext = typeof ZoomPanPinch.prototype;
|
|
16
|
-
|
|
17
|
-
export type ReactZoomPanPinchContextState = {
|
|
18
|
-
instance: ReactZoomPanPinchContext;
|
|
19
|
-
state: ReactZoomPanPinchState;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export type ReactZoomPanPinchContentRef = {
|
|
23
|
-
instance: ReactZoomPanPinchContext;
|
|
24
|
-
} & ReactZoomPanPinchHandlers;
|
|
25
|
-
|
|
26
|
-
export type ReactZoomPanPinchRef = ReactZoomPanPinchContextState &
|
|
27
|
-
ReactZoomPanPinchHandlers;
|
|
28
|
-
|
|
29
|
-
export type ReactZoomPanPinchState = {
|
|
30
|
-
previousScale: number;
|
|
31
|
-
scale: number;
|
|
32
|
-
positionX: number;
|
|
33
|
-
positionY: number;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export type ReactZoomPanPinchHandlers = {
|
|
37
|
-
zoomIn: ReturnType<typeof zoomIn>;
|
|
38
|
-
zoomOut: ReturnType<typeof zoomOut>;
|
|
39
|
-
setTransform: ReturnType<typeof setTransform>;
|
|
40
|
-
resetTransform: ReturnType<typeof resetTransform>;
|
|
41
|
-
centerView: ReturnType<typeof centerView>;
|
|
42
|
-
zoomToElement: ReturnType<typeof zoomToElement>;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type ReactZoomPanPinchRefProps = {
|
|
46
|
-
setRef: (context: ReactZoomPanPinchRef) => void;
|
|
47
|
-
} & Omit<ReactZoomPanPinchProps, "ref">;
|
|
48
|
-
|
|
49
|
-
export type ReactZoomPanPinchProps = {
|
|
50
|
-
children?:
|
|
51
|
-
| React.ReactNode
|
|
52
|
-
| ((ref: ReactZoomPanPinchContentRef) => React.ReactNode);
|
|
53
|
-
ref?: React.Ref<ReactZoomPanPinchRef>;
|
|
54
|
-
initialScale?: number;
|
|
55
|
-
initialPositionX?: number;
|
|
56
|
-
initialPositionY?: number;
|
|
57
|
-
disabled?: boolean;
|
|
58
|
-
minPositionX?: null | number;
|
|
59
|
-
maxPositionX?: null | number;
|
|
60
|
-
minPositionY?: null | number;
|
|
61
|
-
maxPositionY?: null | number;
|
|
62
|
-
minScale?: number;
|
|
63
|
-
maxScale?: number;
|
|
64
|
-
limitToBounds?: boolean;
|
|
65
|
-
centerZoomedOut?: boolean;
|
|
66
|
-
centerOnInit?: boolean;
|
|
67
|
-
disablePadding?: boolean;
|
|
68
|
-
customTransform?: (x: number, y: number, scale: number) => string;
|
|
69
|
-
smooth?: boolean;
|
|
70
|
-
wheel?: {
|
|
71
|
-
step?: number;
|
|
72
|
-
smoothStep?: number;
|
|
73
|
-
disabled?: boolean;
|
|
74
|
-
wheelDisabled?: boolean;
|
|
75
|
-
touchPadDisabled?: boolean;
|
|
76
|
-
activationKeys?: string[];
|
|
77
|
-
excluded?: string[];
|
|
78
|
-
};
|
|
79
|
-
panning?: {
|
|
80
|
-
disabled?: boolean;
|
|
81
|
-
velocityDisabled?: boolean;
|
|
82
|
-
lockAxisX?: boolean;
|
|
83
|
-
lockAxisY?: boolean;
|
|
84
|
-
allowLeftClickPan?: boolean;
|
|
85
|
-
allowMiddleClickPan?: boolean;
|
|
86
|
-
allowRightClickPan?: boolean;
|
|
87
|
-
activationKeys?: string[];
|
|
88
|
-
excluded?: string[];
|
|
89
|
-
};
|
|
90
|
-
pinch?: {
|
|
91
|
-
step?: number;
|
|
92
|
-
disabled?: boolean;
|
|
93
|
-
excluded?: string[];
|
|
94
|
-
};
|
|
95
|
-
doubleClick?: {
|
|
96
|
-
disabled?: boolean;
|
|
97
|
-
step?: number;
|
|
98
|
-
mode?: "zoomIn" | "zoomOut" | "reset";
|
|
99
|
-
animationTime?: number;
|
|
100
|
-
animationType?: keyof typeof animations;
|
|
101
|
-
excluded?: string[];
|
|
102
|
-
};
|
|
103
|
-
zoomAnimation?: {
|
|
104
|
-
disabled?: boolean;
|
|
105
|
-
size?: number;
|
|
106
|
-
animationTime?: number;
|
|
107
|
-
animationType?: keyof typeof animations;
|
|
108
|
-
};
|
|
109
|
-
alignmentAnimation?: {
|
|
110
|
-
disabled?: boolean;
|
|
111
|
-
sizeX?: number;
|
|
112
|
-
sizeY?: number;
|
|
113
|
-
animationTime?: number;
|
|
114
|
-
velocityAlignmentTime?: number;
|
|
115
|
-
animationType?: keyof typeof animations;
|
|
116
|
-
};
|
|
117
|
-
velocityAnimation?: {
|
|
118
|
-
disabled?: boolean;
|
|
119
|
-
sensitivity?: number;
|
|
120
|
-
animationTime?: number;
|
|
121
|
-
animationType?: keyof typeof animations;
|
|
122
|
-
equalToMove?: boolean;
|
|
123
|
-
};
|
|
124
|
-
onWheelStart?: (ref: ReactZoomPanPinchRef, event: WheelEvent) => void;
|
|
125
|
-
onWheel?: (ref: ReactZoomPanPinchRef, event: WheelEvent) => void;
|
|
126
|
-
onWheelStop?: (ref: ReactZoomPanPinchRef, event: WheelEvent) => void;
|
|
127
|
-
onPanningStart?: (
|
|
128
|
-
ref: ReactZoomPanPinchRef,
|
|
129
|
-
event: TouchEvent | MouseEvent,
|
|
130
|
-
) => void;
|
|
131
|
-
onPanning?: (
|
|
132
|
-
ref: ReactZoomPanPinchRef,
|
|
133
|
-
event: TouchEvent | MouseEvent,
|
|
134
|
-
) => void;
|
|
135
|
-
onPanningStop?: (
|
|
136
|
-
ref: ReactZoomPanPinchRef,
|
|
137
|
-
event: TouchEvent | MouseEvent,
|
|
138
|
-
) => void;
|
|
139
|
-
onPinchingStart?: (ref: ReactZoomPanPinchRef, event: TouchEvent) => void;
|
|
140
|
-
onPinching?: (ref: ReactZoomPanPinchRef, event: TouchEvent) => void;
|
|
141
|
-
onPinchingStop?: (ref: ReactZoomPanPinchRef, event: TouchEvent) => void;
|
|
142
|
-
onZoomStart?: (
|
|
143
|
-
ref: ReactZoomPanPinchRef,
|
|
144
|
-
event: TouchEvent | MouseEvent,
|
|
145
|
-
) => void;
|
|
146
|
-
onZoom?: (ref: ReactZoomPanPinchRef, event: TouchEvent | MouseEvent) => void;
|
|
147
|
-
onZoomStop?: (
|
|
148
|
-
ref: ReactZoomPanPinchRef,
|
|
149
|
-
event: TouchEvent | MouseEvent,
|
|
150
|
-
) => void;
|
|
151
|
-
onTransformed?: (
|
|
152
|
-
ref: ReactZoomPanPinchRef,
|
|
153
|
-
state: { scale: number; positionX: number; positionY: number },
|
|
154
|
-
) => void;
|
|
155
|
-
onInit?: (ref: ReactZoomPanPinchRef) => void;
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
export type ReactZoomPanPinchComponentHelpers = {
|
|
159
|
-
setComponents: (wrapper: HTMLDivElement, content: HTMLDivElement) => void;
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
export type LibrarySetup = Pick<
|
|
163
|
-
ReactZoomPanPinchProps,
|
|
164
|
-
"minPositionX" | "maxPositionX" | "minPositionY" | "maxPositionY"
|
|
165
|
-
> &
|
|
166
|
-
DeepNonNullable<
|
|
167
|
-
Omit<
|
|
168
|
-
ReactZoomPanPinchProps,
|
|
169
|
-
| "ref"
|
|
170
|
-
| "initialScale"
|
|
171
|
-
| "initialPositionX"
|
|
172
|
-
| "initialPositionY"
|
|
173
|
-
| "minPositionX"
|
|
174
|
-
| "maxPositionX"
|
|
175
|
-
| "minPositionY"
|
|
176
|
-
| "maxPositionY"
|
|
177
|
-
| "children"
|
|
178
|
-
| "defaultPositionX"
|
|
179
|
-
| "defaultPositionY"
|
|
180
|
-
| "defaultScale"
|
|
181
|
-
| "wrapperClass"
|
|
182
|
-
| "contentClass"
|
|
183
|
-
| "onWheelStart"
|
|
184
|
-
| "onWheel"
|
|
185
|
-
| "onWheelStop"
|
|
186
|
-
| "onPanningStart"
|
|
187
|
-
| "onPanning"
|
|
188
|
-
| "onPanningStop"
|
|
189
|
-
| "onPinchingStart"
|
|
190
|
-
| "onPinching"
|
|
191
|
-
| "onPinchingStop"
|
|
192
|
-
| "onZoomStart"
|
|
193
|
-
| "onZoom"
|
|
194
|
-
| "onZoomStop"
|
|
195
|
-
| "onTransformed"
|
|
196
|
-
| "onInit"
|
|
197
|
-
| "customTransform"
|
|
198
|
-
>
|
|
199
|
-
>;
|