react-zoom-pan-pinch 3.3.0 → 3.4.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/dist/index.cjs.js +46 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.esm.js +46 -3
- 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,188 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react/require-default-props */
|
|
2
|
-
import React, {
|
|
3
|
-
useCallback,
|
|
4
|
-
useEffect,
|
|
5
|
-
useMemo,
|
|
6
|
-
useRef,
|
|
7
|
-
useState,
|
|
8
|
-
} from "react";
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
useTransformContext,
|
|
12
|
-
useTransformEffect,
|
|
13
|
-
useTransformInit,
|
|
14
|
-
} from "hooks";
|
|
15
|
-
import { useResize } from "./use-resize.hook";
|
|
16
|
-
import { ReactZoomPanPinchRef } from "models";
|
|
17
|
-
|
|
18
|
-
export type MiniMapProps = {
|
|
19
|
-
children: React.ReactNode;
|
|
20
|
-
width?: number;
|
|
21
|
-
height?: number;
|
|
22
|
-
borderColor?: string;
|
|
23
|
-
} & React.DetailedHTMLProps<
|
|
24
|
-
React.HTMLAttributes<HTMLDivElement>,
|
|
25
|
-
HTMLDivElement
|
|
26
|
-
>;
|
|
27
|
-
|
|
28
|
-
const previewStyles = {
|
|
29
|
-
position: "absolute",
|
|
30
|
-
zIndex: 2,
|
|
31
|
-
top: "0px",
|
|
32
|
-
left: "0px",
|
|
33
|
-
boxSizing: "border-box",
|
|
34
|
-
border: "3px solid red",
|
|
35
|
-
transformOrigin: "0% 0%",
|
|
36
|
-
boxShadow: "rgba(0,0,0,0.2) 0 0 0 10000000px",
|
|
37
|
-
} as const;
|
|
38
|
-
|
|
39
|
-
export const MiniMap: React.FC<MiniMapProps> = ({
|
|
40
|
-
width = 200,
|
|
41
|
-
height = 200,
|
|
42
|
-
borderColor = "red",
|
|
43
|
-
children,
|
|
44
|
-
...rest
|
|
45
|
-
}) => {
|
|
46
|
-
const [initialized, setInitialized] = useState(false);
|
|
47
|
-
const instance = useTransformContext();
|
|
48
|
-
const miniMapInstance = useRef<ReactZoomPanPinchRef>(null);
|
|
49
|
-
|
|
50
|
-
const mainRef = useRef<HTMLDivElement | null>(null);
|
|
51
|
-
const wrapperRef = useRef<HTMLDivElement | null>(null);
|
|
52
|
-
const previewRef = useRef<HTMLDivElement | null>(null);
|
|
53
|
-
|
|
54
|
-
const getContentSize = useCallback(() => {
|
|
55
|
-
if (instance.contentComponent) {
|
|
56
|
-
const rect = instance.contentComponent.getBoundingClientRect();
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
width: rect.width / instance.transformState.scale,
|
|
60
|
-
height: rect.height / instance.transformState.scale,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
width: 0,
|
|
65
|
-
height: 0,
|
|
66
|
-
};
|
|
67
|
-
}, [instance.contentComponent, instance.transformState.scale]);
|
|
68
|
-
|
|
69
|
-
const computeMiniMapScale = useCallback(() => {
|
|
70
|
-
const contentSize = getContentSize();
|
|
71
|
-
const scaleX = width / contentSize.width;
|
|
72
|
-
const scaleY = height / contentSize.height;
|
|
73
|
-
const scale = scaleY > scaleX ? scaleX : scaleY;
|
|
74
|
-
|
|
75
|
-
return scale;
|
|
76
|
-
}, [getContentSize, height, width]);
|
|
77
|
-
|
|
78
|
-
const computeMiniMapSize = () => {
|
|
79
|
-
const contentSize = getContentSize();
|
|
80
|
-
const scaleX = width / contentSize.width;
|
|
81
|
-
const scaleY = height / contentSize.height;
|
|
82
|
-
if (scaleY > scaleX) {
|
|
83
|
-
return { width, height: contentSize.height * scaleX };
|
|
84
|
-
}
|
|
85
|
-
return { width: contentSize.width * scaleY, height };
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const computeMiniMapStyle = () => {
|
|
89
|
-
const scale = computeMiniMapScale();
|
|
90
|
-
const style = {
|
|
91
|
-
transform: `scale(${scale || 1})`,
|
|
92
|
-
transformOrigin: "0% 0%",
|
|
93
|
-
position: "absolute",
|
|
94
|
-
boxSizing: "border-box",
|
|
95
|
-
zIndex: 1,
|
|
96
|
-
overflow: "hidden",
|
|
97
|
-
} as const;
|
|
98
|
-
|
|
99
|
-
Object.keys(style).forEach((key) => {
|
|
100
|
-
if (wrapperRef.current) {
|
|
101
|
-
wrapperRef.current.style[key] = style[key];
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const transformMiniMap = () => {
|
|
107
|
-
computeMiniMapStyle();
|
|
108
|
-
const miniSize = computeMiniMapSize();
|
|
109
|
-
const wrapSize = getContentSize();
|
|
110
|
-
if (wrapperRef.current) {
|
|
111
|
-
wrapperRef.current.style.width = `${wrapSize.width}px`;
|
|
112
|
-
wrapperRef.current.style.height = `${wrapSize.height}px`;
|
|
113
|
-
}
|
|
114
|
-
if (mainRef.current) {
|
|
115
|
-
mainRef.current.style.width = `${miniSize.width}px`;
|
|
116
|
-
mainRef.current.style.height = `${miniSize.height}px`;
|
|
117
|
-
}
|
|
118
|
-
if (previewRef.current) {
|
|
119
|
-
const size = getContentSize();
|
|
120
|
-
const scale = computeMiniMapScale();
|
|
121
|
-
const previewScale = scale * (1 / instance.transformState.scale);
|
|
122
|
-
const transform = instance.handleTransformStyles(
|
|
123
|
-
-instance.transformState.positionX * previewScale,
|
|
124
|
-
-instance.transformState.positionY * previewScale,
|
|
125
|
-
1,
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
previewRef.current.style.transform = transform;
|
|
129
|
-
previewRef.current.style.width = `${size.width * previewScale}px`;
|
|
130
|
-
previewRef.current.style.height = `${size.height * previewScale}px`;
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const initialize = () => {
|
|
135
|
-
transformMiniMap();
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
useTransformEffect(() => {
|
|
139
|
-
transformMiniMap();
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
useTransformInit(() => {
|
|
143
|
-
initialize();
|
|
144
|
-
setInitialized(true);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
useResize(instance.contentComponent, initialize, [initialized]);
|
|
148
|
-
|
|
149
|
-
useEffect(() => {
|
|
150
|
-
return instance.onChange((zpp) => {
|
|
151
|
-
const scale = computeMiniMapScale();
|
|
152
|
-
if (miniMapInstance.current) {
|
|
153
|
-
miniMapInstance.current.instance.transformState.scale =
|
|
154
|
-
zpp.instance.transformState.scale;
|
|
155
|
-
miniMapInstance.current.instance.transformState.positionX =
|
|
156
|
-
zpp.instance.transformState.positionX * scale;
|
|
157
|
-
miniMapInstance.current.instance.transformState.positionY =
|
|
158
|
-
zpp.instance.transformState.positionY * scale;
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}, [computeMiniMapScale, instance, miniMapInstance]);
|
|
162
|
-
|
|
163
|
-
const wrapperStyle = useMemo(() => {
|
|
164
|
-
return {
|
|
165
|
-
position: "relative",
|
|
166
|
-
zIndex: 2,
|
|
167
|
-
overflow: "hidden",
|
|
168
|
-
} as const;
|
|
169
|
-
}, []);
|
|
170
|
-
|
|
171
|
-
return (
|
|
172
|
-
<div
|
|
173
|
-
{...rest}
|
|
174
|
-
ref={mainRef}
|
|
175
|
-
style={wrapperStyle}
|
|
176
|
-
className={`rzpp-mini-map ${rest.className || ""}`}
|
|
177
|
-
>
|
|
178
|
-
<div {...rest} ref={wrapperRef} className="rzpp-wrapper">
|
|
179
|
-
{children}
|
|
180
|
-
</div>
|
|
181
|
-
<div
|
|
182
|
-
className="rzpp-preview"
|
|
183
|
-
ref={previewRef}
|
|
184
|
-
style={{ ...previewStyles, borderColor }}
|
|
185
|
-
/>
|
|
186
|
-
</div>
|
|
187
|
-
);
|
|
188
|
-
};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect, useRef } from "react";
|
|
2
|
-
|
|
3
|
-
export type NonNullableKeys<T> = {
|
|
4
|
-
[P in keyof T]-?: NonNullable<T[P]>;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export type Nullable<T> = T | null;
|
|
8
|
-
|
|
9
|
-
export type ElementRect = Omit<DOMRect, "toJSON">;
|
|
10
|
-
|
|
11
|
-
const initialElementRect: ElementRect = {
|
|
12
|
-
width: 0,
|
|
13
|
-
height: 0,
|
|
14
|
-
y: 0,
|
|
15
|
-
x: 0,
|
|
16
|
-
top: 0,
|
|
17
|
-
bottom: 0,
|
|
18
|
-
left: 0,
|
|
19
|
-
right: 0,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
type ResizeHandler<T extends HTMLElement> = (
|
|
23
|
-
elementRect: ElementRect,
|
|
24
|
-
element: T,
|
|
25
|
-
) => void;
|
|
26
|
-
|
|
27
|
-
export const useResize = <T extends HTMLElement>(
|
|
28
|
-
ref: Nullable<T>,
|
|
29
|
-
onResize: ResizeHandler<T>,
|
|
30
|
-
dependencies: any[],
|
|
31
|
-
) => {
|
|
32
|
-
const resizeObserverRef = useRef<ResizeObserver>();
|
|
33
|
-
|
|
34
|
-
const rectRef = useRef(initialElementRect);
|
|
35
|
-
|
|
36
|
-
const didUnmount = useRef(false);
|
|
37
|
-
|
|
38
|
-
useLayoutEffect(() => {
|
|
39
|
-
didUnmount.current = false;
|
|
40
|
-
if (ref) {
|
|
41
|
-
resizeObserverRef.current = new ResizeObserver(
|
|
42
|
-
(entries: ResizeObserverEntry[]) => {
|
|
43
|
-
const newSize = ref.getBoundingClientRect();
|
|
44
|
-
if (
|
|
45
|
-
!Array.isArray(entries) ||
|
|
46
|
-
!entries.length ||
|
|
47
|
-
didUnmount.current ||
|
|
48
|
-
(newSize.width === rectRef.current.width &&
|
|
49
|
-
newSize.height === rectRef.current.height)
|
|
50
|
-
)
|
|
51
|
-
return;
|
|
52
|
-
|
|
53
|
-
onResize(newSize, ref);
|
|
54
|
-
rectRef.current = newSize;
|
|
55
|
-
},
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
resizeObserverRef.current?.observe(ref);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return () => {
|
|
62
|
-
didUnmount.current = true;
|
|
63
|
-
if (ref) {
|
|
64
|
-
resizeObserverRef.current?.unobserve(ref);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
68
|
-
}, [onResize, ref, ...dependencies]);
|
|
69
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
.wrapper {
|
|
2
|
-
position: relative;
|
|
3
|
-
width: -moz-fit-content;
|
|
4
|
-
width: fit-content;
|
|
5
|
-
height: -moz-fit-content;
|
|
6
|
-
height: fit-content;
|
|
7
|
-
overflow: hidden;
|
|
8
|
-
-webkit-touch-callout: none; /* iOS Safari */
|
|
9
|
-
-webkit-user-select: none; /* Safari */
|
|
10
|
-
-khtml-user-select: none; /* Konqueror HTML */
|
|
11
|
-
-moz-user-select: none; /* Firefox */
|
|
12
|
-
-ms-user-select: none; /* Internet Explorer/Edge */
|
|
13
|
-
user-select: none;
|
|
14
|
-
margin: 0;
|
|
15
|
-
padding: 0;
|
|
16
|
-
}
|
|
17
|
-
.content {
|
|
18
|
-
display: flex;
|
|
19
|
-
flex-wrap: wrap;
|
|
20
|
-
width: -moz-fit-content;
|
|
21
|
-
width: fit-content;
|
|
22
|
-
height: -moz-fit-content;
|
|
23
|
-
height: fit-content;
|
|
24
|
-
margin: 0;
|
|
25
|
-
padding: 0;
|
|
26
|
-
transform-origin: 0% 0%;
|
|
27
|
-
}
|
|
28
|
-
.content img {
|
|
29
|
-
pointer-events: none;
|
|
30
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react/require-default-props */
|
|
2
|
-
import React, { useContext, useEffect, useRef } from "react";
|
|
3
|
-
|
|
4
|
-
import { Context } from "../transform-wrapper/transform-wrapper";
|
|
5
|
-
|
|
6
|
-
import styles from "./transform-component.module.css";
|
|
7
|
-
|
|
8
|
-
type Props = {
|
|
9
|
-
children: React.ReactNode;
|
|
10
|
-
wrapperClass?: string;
|
|
11
|
-
contentClass?: string;
|
|
12
|
-
wrapperStyle?: React.CSSProperties;
|
|
13
|
-
contentStyle?: React.CSSProperties;
|
|
14
|
-
wrapperProps?: React.HTMLAttributes<HTMLDivElement>;
|
|
15
|
-
contentProps?: React.HTMLAttributes<HTMLDivElement>;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const TransformComponent: React.FC<Props> = ({
|
|
19
|
-
children,
|
|
20
|
-
wrapperClass = "",
|
|
21
|
-
contentClass = "",
|
|
22
|
-
wrapperStyle,
|
|
23
|
-
contentStyle,
|
|
24
|
-
wrapperProps = {},
|
|
25
|
-
contentProps = {},
|
|
26
|
-
}: Props) => {
|
|
27
|
-
const { init, cleanupWindowEvents } = useContext(Context);
|
|
28
|
-
|
|
29
|
-
const wrapperRef = useRef<HTMLDivElement | null>(null);
|
|
30
|
-
const contentRef = useRef<HTMLDivElement | null>(null);
|
|
31
|
-
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
const wrapper = wrapperRef.current;
|
|
34
|
-
const content = contentRef.current;
|
|
35
|
-
if (wrapper !== null && content !== null && init) {
|
|
36
|
-
init?.(wrapper, content);
|
|
37
|
-
}
|
|
38
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
39
|
-
return () => {
|
|
40
|
-
cleanupWindowEvents?.();
|
|
41
|
-
};
|
|
42
|
-
}, []);
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<div
|
|
46
|
-
{...wrapperProps}
|
|
47
|
-
ref={wrapperRef}
|
|
48
|
-
className={`react-transform-wrapper ${styles.wrapper} ${wrapperClass}`}
|
|
49
|
-
style={wrapperStyle}
|
|
50
|
-
>
|
|
51
|
-
<div
|
|
52
|
-
{...contentProps}
|
|
53
|
-
ref={contentRef}
|
|
54
|
-
className={`react-transform-component ${styles.content} ${contentClass}`}
|
|
55
|
-
style={contentStyle}
|
|
56
|
-
>
|
|
57
|
-
{children}
|
|
58
|
-
</div>
|
|
59
|
-
</div>
|
|
60
|
-
);
|
|
61
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useImperativeHandle, useRef } from "react";
|
|
2
|
-
|
|
3
|
-
import { ZoomPanPinch } from "../../core/instance.core";
|
|
4
|
-
import {
|
|
5
|
-
ReactZoomPanPinchContentRef,
|
|
6
|
-
ReactZoomPanPinchProps,
|
|
7
|
-
} from "../../models";
|
|
8
|
-
import { getControls } from "../../utils";
|
|
9
|
-
|
|
10
|
-
export const Context = React.createContext<ZoomPanPinch>(null as any);
|
|
11
|
-
|
|
12
|
-
const getContent = (
|
|
13
|
-
children: ReactZoomPanPinchProps["children"],
|
|
14
|
-
ctx: ReactZoomPanPinchContentRef,
|
|
15
|
-
) => {
|
|
16
|
-
if (typeof children === "function") {
|
|
17
|
-
return children(ctx);
|
|
18
|
-
}
|
|
19
|
-
return children;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const TransformWrapper = React.forwardRef(
|
|
23
|
-
(
|
|
24
|
-
props: Omit<ReactZoomPanPinchProps, "ref">,
|
|
25
|
-
ref: React.Ref<ReactZoomPanPinchContentRef>,
|
|
26
|
-
) => {
|
|
27
|
-
const instance = useRef(new ZoomPanPinch(props)).current;
|
|
28
|
-
|
|
29
|
-
const content = getContent(props.children, getControls(instance));
|
|
30
|
-
|
|
31
|
-
useImperativeHandle(ref, () => getControls(instance), [instance]);
|
|
32
|
-
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
instance.update(props);
|
|
35
|
-
}, [instance, props]);
|
|
36
|
-
|
|
37
|
-
return <Context.Provider value={instance}>{content}</Context.Provider>;
|
|
38
|
-
},
|
|
39
|
-
);
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { LibrarySetup, ReactZoomPanPinchState } from "../models/context.model";
|
|
2
|
-
|
|
3
|
-
export const initialState: ReactZoomPanPinchState = {
|
|
4
|
-
previousScale: 1,
|
|
5
|
-
scale: 1,
|
|
6
|
-
positionX: 0,
|
|
7
|
-
positionY: 0,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const initialSetup: LibrarySetup = {
|
|
11
|
-
disabled: false,
|
|
12
|
-
minPositionX: null,
|
|
13
|
-
maxPositionX: null,
|
|
14
|
-
minPositionY: null,
|
|
15
|
-
maxPositionY: null,
|
|
16
|
-
minScale: 1,
|
|
17
|
-
maxScale: 8,
|
|
18
|
-
limitToBounds: true,
|
|
19
|
-
centerZoomedOut: false,
|
|
20
|
-
centerOnInit: false,
|
|
21
|
-
disablePadding: false,
|
|
22
|
-
smooth: true,
|
|
23
|
-
wheel: {
|
|
24
|
-
step: 0.2,
|
|
25
|
-
disabled: false,
|
|
26
|
-
smoothStep: 0.001,
|
|
27
|
-
wheelDisabled: false,
|
|
28
|
-
touchPadDisabled: false,
|
|
29
|
-
activationKeys: [],
|
|
30
|
-
excluded: [],
|
|
31
|
-
},
|
|
32
|
-
panning: {
|
|
33
|
-
disabled: false,
|
|
34
|
-
velocityDisabled: false,
|
|
35
|
-
lockAxisX: false,
|
|
36
|
-
lockAxisY: false,
|
|
37
|
-
allowLeftClickPan: true,
|
|
38
|
-
allowMiddleClickPan: true,
|
|
39
|
-
allowRightClickPan: true,
|
|
40
|
-
activationKeys: [],
|
|
41
|
-
excluded: [],
|
|
42
|
-
},
|
|
43
|
-
pinch: {
|
|
44
|
-
step: 5,
|
|
45
|
-
disabled: false,
|
|
46
|
-
excluded: [],
|
|
47
|
-
},
|
|
48
|
-
doubleClick: {
|
|
49
|
-
disabled: false,
|
|
50
|
-
step: 0.7,
|
|
51
|
-
mode: "zoomIn",
|
|
52
|
-
animationType: "easeOut",
|
|
53
|
-
animationTime: 200,
|
|
54
|
-
excluded: [],
|
|
55
|
-
},
|
|
56
|
-
zoomAnimation: {
|
|
57
|
-
disabled: false,
|
|
58
|
-
size: 0.4,
|
|
59
|
-
animationTime: 200,
|
|
60
|
-
animationType: "easeOut",
|
|
61
|
-
},
|
|
62
|
-
alignmentAnimation: {
|
|
63
|
-
disabled: false,
|
|
64
|
-
sizeX: 100,
|
|
65
|
-
sizeY: 100,
|
|
66
|
-
animationTime: 200,
|
|
67
|
-
velocityAlignmentTime: 400,
|
|
68
|
-
animationType: "easeOut",
|
|
69
|
-
},
|
|
70
|
-
velocityAnimation: {
|
|
71
|
-
disabled: false,
|
|
72
|
-
sensitivity: 1,
|
|
73
|
-
animationTime: 400,
|
|
74
|
-
animationType: "easeOut",
|
|
75
|
-
equalToMove: true,
|
|
76
|
-
},
|
|
77
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-plusplus */
|
|
2
|
-
/* eslint-disable no-param-reassign */
|
|
3
|
-
/**
|
|
4
|
-
* Functions should return denominator of the target value, which is the next animation step.
|
|
5
|
-
* t is a value from 0 to 1, reflecting the percentage of animation status.
|
|
6
|
-
*/
|
|
7
|
-
const easeOut = (t: number): number => {
|
|
8
|
-
return -Math.cos(t * Math.PI) / 2 + 0.5;
|
|
9
|
-
};
|
|
10
|
-
// linear
|
|
11
|
-
const linear = (t: number): number => {
|
|
12
|
-
return t;
|
|
13
|
-
};
|
|
14
|
-
// accelerating from zero velocity
|
|
15
|
-
const easeInQuad = (t: number): number => {
|
|
16
|
-
return t * t;
|
|
17
|
-
};
|
|
18
|
-
// decelerating to zero velocity
|
|
19
|
-
const easeOutQuad = (t: number): number => {
|
|
20
|
-
return t * (2 - t);
|
|
21
|
-
};
|
|
22
|
-
// acceleration until halfway, then deceleration
|
|
23
|
-
const easeInOutQuad = (t: number): number => {
|
|
24
|
-
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
|
|
25
|
-
};
|
|
26
|
-
// accelerating from zero velocity
|
|
27
|
-
const easeInCubic = (t: number): number => {
|
|
28
|
-
return t * t * t;
|
|
29
|
-
};
|
|
30
|
-
// decelerating to zero velocity
|
|
31
|
-
const easeOutCubic = (t: number): number => {
|
|
32
|
-
return --t * t * t + 1;
|
|
33
|
-
};
|
|
34
|
-
// acceleration until halfway, then deceleration
|
|
35
|
-
const easeInOutCubic = (t: number): number => {
|
|
36
|
-
return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
|
|
37
|
-
};
|
|
38
|
-
// accelerating from zero velocity
|
|
39
|
-
const easeInQuart = (t: number): number => {
|
|
40
|
-
return t * t * t * t;
|
|
41
|
-
};
|
|
42
|
-
// decelerating to zero velocity
|
|
43
|
-
const easeOutQuart = (t: number): number => {
|
|
44
|
-
return 1 - --t * t * t * t;
|
|
45
|
-
};
|
|
46
|
-
// acceleration until halfway, then deceleration
|
|
47
|
-
const easeInOutQuart = (t: number): number => {
|
|
48
|
-
return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t;
|
|
49
|
-
};
|
|
50
|
-
// accelerating from zero velocity
|
|
51
|
-
const easeInQuint = (t: number): number => {
|
|
52
|
-
return t * t * t * t * t;
|
|
53
|
-
};
|
|
54
|
-
// decelerating to zero velocity
|
|
55
|
-
const easeOutQuint = function (t: number): number {
|
|
56
|
-
return 1 + --t * t * t * t * t;
|
|
57
|
-
};
|
|
58
|
-
// acceleration until halfway, then deceleration
|
|
59
|
-
const easeInOutQuint = function (t: number): number {
|
|
60
|
-
return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const animations = {
|
|
64
|
-
easeOut,
|
|
65
|
-
linear,
|
|
66
|
-
easeInQuad,
|
|
67
|
-
easeOutQuad,
|
|
68
|
-
easeInOutQuad,
|
|
69
|
-
easeInCubic,
|
|
70
|
-
easeOutCubic,
|
|
71
|
-
easeInOutCubic,
|
|
72
|
-
easeInQuart,
|
|
73
|
-
easeOutQuart,
|
|
74
|
-
easeInOutQuart,
|
|
75
|
-
easeInQuint,
|
|
76
|
-
easeOutQuint,
|
|
77
|
-
easeInOutQuint,
|
|
78
|
-
};
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */
|
|
2
|
-
import { animations } from "./animations.constants";
|
|
3
|
-
import {
|
|
4
|
-
AnimationType,
|
|
5
|
-
ReactZoomPanPinchContext,
|
|
6
|
-
StateType,
|
|
7
|
-
} from "../../models";
|
|
8
|
-
|
|
9
|
-
const handleCancelAnimationFrame = (animation: AnimationType | null) => {
|
|
10
|
-
if (typeof animation === "number") {
|
|
11
|
-
cancelAnimationFrame(animation);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const handleCancelAnimation = (
|
|
16
|
-
contextInstance: ReactZoomPanPinchContext,
|
|
17
|
-
): void => {
|
|
18
|
-
if (!contextInstance.mounted) return;
|
|
19
|
-
handleCancelAnimationFrame(contextInstance.animation);
|
|
20
|
-
// Clear animation state
|
|
21
|
-
contextInstance.animate = false;
|
|
22
|
-
contextInstance.animation = null;
|
|
23
|
-
contextInstance.velocity = null;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export function handleSetupAnimation(
|
|
27
|
-
contextInstance: ReactZoomPanPinchContext,
|
|
28
|
-
animationName: string,
|
|
29
|
-
animationTime: number,
|
|
30
|
-
callback: (step: number) => void,
|
|
31
|
-
): void {
|
|
32
|
-
if (!contextInstance.mounted) return;
|
|
33
|
-
const startTime = new Date().getTime();
|
|
34
|
-
const lastStep = 1;
|
|
35
|
-
|
|
36
|
-
// if another animation is active
|
|
37
|
-
handleCancelAnimation(contextInstance);
|
|
38
|
-
|
|
39
|
-
// new animation
|
|
40
|
-
contextInstance.animation = () => {
|
|
41
|
-
if (!contextInstance.mounted) {
|
|
42
|
-
return handleCancelAnimationFrame(contextInstance.animation);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const frameTime = new Date().getTime() - startTime;
|
|
46
|
-
const animationProgress = frameTime / animationTime;
|
|
47
|
-
const animationType = animations[animationName];
|
|
48
|
-
|
|
49
|
-
const step = animationType(animationProgress);
|
|
50
|
-
|
|
51
|
-
if (frameTime >= animationTime) {
|
|
52
|
-
callback(lastStep);
|
|
53
|
-
contextInstance.animation = null;
|
|
54
|
-
} else if (contextInstance.animation) {
|
|
55
|
-
callback(step);
|
|
56
|
-
requestAnimationFrame(contextInstance.animation);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
requestAnimationFrame(contextInstance.animation);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function isValidTargetState(targetState: StateType): boolean {
|
|
64
|
-
const { scale, positionX, positionY } = targetState;
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
Number.isNaN(scale) ||
|
|
68
|
-
Number.isNaN(positionX) ||
|
|
69
|
-
Number.isNaN(positionY)
|
|
70
|
-
) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function animate(
|
|
78
|
-
contextInstance: ReactZoomPanPinchContext,
|
|
79
|
-
targetState: StateType,
|
|
80
|
-
animationTime: number,
|
|
81
|
-
animationName: string,
|
|
82
|
-
): void {
|
|
83
|
-
const isValid = isValidTargetState(targetState);
|
|
84
|
-
if (!contextInstance.mounted || !isValid) return;
|
|
85
|
-
|
|
86
|
-
const { setTransformState } = contextInstance;
|
|
87
|
-
const { scale, positionX, positionY } = contextInstance.transformState;
|
|
88
|
-
|
|
89
|
-
const scaleDiff = targetState.scale - scale;
|
|
90
|
-
const positionXDiff = targetState.positionX - positionX;
|
|
91
|
-
const positionYDiff = targetState.positionY - positionY;
|
|
92
|
-
|
|
93
|
-
if (animationTime === 0) {
|
|
94
|
-
setTransformState(
|
|
95
|
-
targetState.scale,
|
|
96
|
-
targetState.positionX,
|
|
97
|
-
targetState.positionY,
|
|
98
|
-
);
|
|
99
|
-
} else {
|
|
100
|
-
// animation start timestamp
|
|
101
|
-
handleSetupAnimation(
|
|
102
|
-
contextInstance,
|
|
103
|
-
animationName,
|
|
104
|
-
animationTime,
|
|
105
|
-
(step: number) => {
|
|
106
|
-
const newScale = scale + scaleDiff * step;
|
|
107
|
-
const newPositionX = positionX + positionXDiff * step;
|
|
108
|
-
const newPositionY = positionY + positionYDiff * step;
|
|
109
|
-
|
|
110
|
-
setTransformState(newScale, newPositionX, newPositionY);
|
|
111
|
-
},
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
}
|