react-zoom-pan-pinch 3.2.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.
Files changed (186) hide show
  1. package/dist/index.cjs.js +54 -33
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.d.ts +6 -0
  4. package/dist/index.esm.js +54 -33
  5. package/dist/index.esm.js.map +1 -1
  6. package/package.json +4 -1
  7. package/.eslintignore +0 -6
  8. package/.github/CODEOWNERS +0 -36
  9. package/.github/FUNDING.yml +0 -13
  10. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  11. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  12. package/.github/workflows/docs.yml +0 -34
  13. package/.github/workflows/release.yml +0 -46
  14. package/.github/workflows/tests.yml +0 -42
  15. package/.prettierrc +0 -10
  16. package/.releaserc.json +0 -63
  17. package/.storybook/main.js +0 -23
  18. package/.storybook/preview-head.html +0 -5
  19. package/.storybook/preview.js +0 -11
  20. package/.storybook/theme-overrides.css +0 -49
  21. package/CHANGELOG.md +0 -26
  22. package/Code_of_Conduct.md +0 -61
  23. package/Contributing.md +0 -236
  24. package/__tests__/features/props.spec.tsx +0 -11
  25. package/__tests__/features/rendering.spec.tsx +0 -36
  26. package/__tests__/shared/render.shared.tsx +0 -41
  27. package/__tests__/utils/controls.utils.tsx +0 -25
  28. package/__tests__/utils/example.tsx +0 -81
  29. package/commitlint.config.js +0 -1
  30. package/dist/__tests__/features/props.spec.d.ts +0 -1
  31. package/dist/__tests__/features/rendering.spec.d.ts +0 -1
  32. package/dist/__tests__/shared/render.shared.d.ts +0 -11
  33. package/dist/__tests__/utils/controls.utils.d.ts +0 -3
  34. package/dist/__tests__/utils/example.d.ts +0 -6
  35. package/dist/src/components/index.d.ts +0 -4
  36. package/dist/src/components/keep-scale/keep-scale.d.ts +0 -2
  37. package/dist/src/components/mini-map/mini-map.d.ts +0 -8
  38. package/dist/src/components/mini-map/use-resize.hook.d.ts +0 -8
  39. package/dist/src/components/transform-component/transform-component.d.ts +0 -12
  40. package/dist/src/components/transform-wrapper/transform-wrapper.d.ts +0 -5
  41. package/dist/src/constants/state.constants.d.ts +0 -3
  42. package/dist/src/core/animations/animations.constants.d.ts +0 -16
  43. package/dist/src/core/animations/animations.utils.d.ts +0 -4
  44. package/dist/src/core/bounds/bounds.types.d.ts +0 -8
  45. package/dist/src/core/bounds/bounds.utils.d.ts +0 -17
  46. package/dist/src/core/double-click/double-click.logic.d.ts +0 -5
  47. package/dist/src/core/handlers/handlers.logic.d.ts +0 -8
  48. package/dist/src/core/handlers/handlers.utils.d.ts +0 -14
  49. package/dist/src/core/instance.core.d.ts +0 -77
  50. package/dist/src/core/pan/panning.logic.d.ts +0 -5
  51. package/dist/src/core/pan/panning.utils.d.ts +0 -10
  52. package/dist/src/core/pan/velocity.logic.d.ts +0 -5
  53. package/dist/src/core/pan/velocity.utils.d.ts +0 -5
  54. package/dist/src/core/pinch/pinch.logic.d.ts +0 -4
  55. package/dist/src/core/pinch/pinch.utils.d.ts +0 -6
  56. package/dist/src/core/wheel/wheel.logic.d.ts +0 -4
  57. package/dist/src/core/wheel/wheel.utils.d.ts +0 -7
  58. package/dist/src/core/zoom/zoom.logic.d.ts +0 -3
  59. package/dist/src/core/zoom/zoom.utils.d.ts +0 -3
  60. package/dist/src/hooks/index.d.ts +0 -4
  61. package/dist/src/hooks/use-controls.d.ts +0 -2
  62. package/dist/src/hooks/use-transform-context.d.ts +0 -1
  63. package/dist/src/hooks/use-transform-effect.d.ts +0 -2
  64. package/dist/src/hooks/use-transform-init.d.ts +0 -2
  65. package/dist/src/index.d.ts +0 -5
  66. package/dist/src/models/calculations.model.d.ts +0 -25
  67. package/dist/src/models/context.model.d.ts +0 -124
  68. package/dist/src/models/helpers.model.d.ts +0 -5
  69. package/dist/src/models/index.d.ts +0 -3
  70. package/dist/src/stories/docs/handlers.d.ts +0 -12
  71. package/dist/src/stories/docs/props.d.ts +0 -14
  72. package/dist/src/stories/examples/content-rerendering/example.d.ts +0 -2
  73. package/dist/src/stories/examples/image-responsive/example.d.ts +0 -2
  74. package/dist/src/stories/examples/keep-scale/example.d.ts +0 -2
  75. package/dist/src/stories/examples/mini-map/example.d.ts +0 -1
  76. package/dist/src/stories/examples/stress/example.d.ts +0 -2
  77. package/dist/src/stories/examples/svg-zoom-to-element/example.d.ts +0 -2
  78. package/dist/src/stories/examples/zoom-to-element/example.d.ts +0 -2
  79. package/dist/src/stories/types/args.types.d.ts +0 -280
  80. package/dist/src/stories/utils/args.utils.d.ts +0 -3
  81. package/dist/src/stories/utils/code.utils.d.ts +0 -6
  82. package/dist/src/stories/utils/controls.utils.d.ts +0 -3
  83. package/dist/src/stories/utils/index.d.ts +0 -3
  84. package/dist/src/utils/calculations.utils.d.ts +0 -11
  85. package/dist/src/utils/callback.utils.d.ts +0 -2
  86. package/dist/src/utils/context.utils.d.ts +0 -4
  87. package/dist/src/utils/event.utils.d.ts +0 -1
  88. package/dist/src/utils/helpers.utils.d.ts +0 -2
  89. package/dist/src/utils/index.d.ts +0 -8
  90. package/dist/src/utils/ref.utils.d.ts +0 -2
  91. package/dist/src/utils/state.utils.d.ts +0 -3
  92. package/dist/src/utils/styles.utils.d.ts +0 -4
  93. package/jest.config.ts +0 -45
  94. package/rollup.config.js +0 -51
  95. package/src/.eslintrc.json +0 -90
  96. package/src/components/index.ts +0 -4
  97. package/src/components/keep-scale/keep-scale.tsx +0 -28
  98. package/src/components/mini-map/mini-map.tsx +0 -188
  99. package/src/components/mini-map/use-resize.hook.ts +0 -69
  100. package/src/components/transform-component/transform-component.module.css +0 -30
  101. package/src/components/transform-component/transform-component.tsx +0 -58
  102. package/src/components/transform-wrapper/transform-wrapper.tsx +0 -42
  103. package/src/constants/state.constants.ts +0 -74
  104. package/src/core/animations/animations.constants.ts +0 -78
  105. package/src/core/animations/animations.utils.ts +0 -114
  106. package/src/core/bounds/bounds.types.ts +0 -8
  107. package/src/core/bounds/bounds.utils.ts +0 -198
  108. package/src/core/double-click/double-click.logic.ts +0 -116
  109. package/src/core/handlers/handlers.logic.ts +0 -115
  110. package/src/core/handlers/handlers.utils.ts +0 -195
  111. package/src/core/instance.core.ts +0 -499
  112. package/src/core/pan/panning.logic.ts +0 -100
  113. package/src/core/pan/panning.utils.ts +0 -196
  114. package/src/core/pan/velocity.logic.ts +0 -149
  115. package/src/core/pan/velocity.utils.ts +0 -79
  116. package/src/core/pinch/pinch.logic.ts +0 -81
  117. package/src/core/pinch/pinch.utils.ts +0 -88
  118. package/src/core/wheel/wheel.logic.ts +0 -121
  119. package/src/core/wheel/wheel.utils.ts +0 -122
  120. package/src/core/zoom/zoom.logic.ts +0 -69
  121. package/src/core/zoom/zoom.utils.ts +0 -58
  122. package/src/hooks/index.ts +0 -4
  123. package/src/hooks/use-controls.tsx +0 -9
  124. package/src/hooks/use-transform-context.tsx +0 -13
  125. package/src/hooks/use-transform-effect.tsx +0 -22
  126. package/src/hooks/use-transform-init.tsx +0 -27
  127. package/src/index.ts +0 -6
  128. package/src/models/calculations.model.ts +0 -26
  129. package/src/models/context.model.ts +0 -196
  130. package/src/models/helpers.model.ts +0 -15
  131. package/src/models/index.ts +0 -3
  132. package/src/react-app-env.d.ts +0 -1
  133. package/src/stories/assets/big-image.jpeg +0 -0
  134. package/src/stories/assets/map.jpg +0 -0
  135. package/src/stories/assets/medium-image.jpg +0 -0
  136. package/src/stories/assets/pin.svg +0 -1
  137. package/src/stories/assets/small-image.jpg +0 -0
  138. package/src/stories/assets/svg-example.svg +0 -14
  139. package/src/stories/docs/Introduction.stories.mdx +0 -174
  140. package/src/stories/docs/handlers.stories.mdx +0 -48
  141. package/src/stories/docs/handlers.tsx +0 -107
  142. package/src/stories/docs/props.stories.mdx +0 -92
  143. package/src/stories/docs/props.tsx +0 -508
  144. package/src/stories/examples/content/content.stories.mdx +0 -121
  145. package/src/stories/examples/content-rerendering/content-updating.stories.mdx +0 -45
  146. package/src/stories/examples/content-rerendering/example.tsx +0 -73
  147. package/src/stories/examples/controls/controls.stories.mdx +0 -71
  148. package/src/stories/examples/image-big/image-big.stories.mdx +0 -43
  149. package/src/stories/examples/image-medium/image-medium.stories.mdx +0 -41
  150. package/src/stories/examples/image-responsive/example.tsx +0 -103
  151. package/src/stories/examples/image-responsive/image-responsive.stories.mdx +0 -32
  152. package/src/stories/examples/image-small/image-small.stories.mdx +0 -41
  153. package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +0 -46
  154. package/src/stories/examples/keep-scale/example.tsx +0 -92
  155. package/src/stories/examples/keep-scale/keep-scale.stories.mdx +0 -45
  156. package/src/stories/examples/mini-map/example.tsx +0 -54
  157. package/src/stories/examples/mini-map/mini-map.stories.mdx +0 -33
  158. package/src/stories/examples/stress/example.tsx +0 -23
  159. package/src/stories/examples/stress/stress-test.stories.mdx +0 -28
  160. package/src/stories/examples/svg-zoom-to-element/creativity.svg +0 -143
  161. package/src/stories/examples/svg-zoom-to-element/example.tsx +0 -57
  162. package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +0 -28
  163. package/src/stories/examples/zoom-to-element/example.tsx +0 -94
  164. package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +0 -28
  165. package/src/stories/hooks/use-controls.stories.mdx +0 -24
  166. package/src/stories/hooks/use-transform-context.stories.mdx +0 -15
  167. package/src/stories/hooks/use-transform-effect.stories.mdx +0 -29
  168. package/src/stories/hooks/use-transform-init.stories.mdx +0 -25
  169. package/src/stories/types/args.types.ts +0 -211
  170. package/src/stories/utils/args.utils.ts +0 -34
  171. package/src/stories/utils/code.utils.tsx +0 -24
  172. package/src/stories/utils/controls.utils.tsx +0 -43
  173. package/src/stories/utils/index.ts +0 -3
  174. package/src/stories/utils/styles.module.css +0 -34
  175. package/src/styles.css +0 -8
  176. package/src/typings.d.ts +0 -10
  177. package/src/utils/calculations.utils.ts +0 -16
  178. package/src/utils/callback.utils.ts +0 -11
  179. package/src/utils/context.utils.ts +0 -48
  180. package/src/utils/event.utils.ts +0 -22
  181. package/src/utils/helpers.utils.ts +0 -27
  182. package/src/utils/index.ts +0 -8
  183. package/src/utils/ref.utils.ts +0 -16
  184. package/src/utils/state.utils.ts +0 -40
  185. package/src/utils/styles.utils.ts +0 -44
  186. 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,58 +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 } = 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
- }, []);
40
-
41
- return (
42
- <div
43
- {...wrapperProps}
44
- ref={wrapperRef}
45
- className={`react-transform-wrapper ${styles.wrapper} ${wrapperClass}`}
46
- style={wrapperStyle}
47
- >
48
- <div
49
- {...contentProps}
50
- ref={contentRef}
51
- className={`react-transform-component ${styles.content} ${contentClass}`}
52
- style={contentStyle}
53
- >
54
- {children}
55
- </div>
56
- </div>
57
- );
58
- };
@@ -1,42 +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
- return () => {
36
- instance.cleanupWindowEvents();
37
- };
38
- }, [instance, props]);
39
-
40
- return <Context.Provider value={instance}>{content}</Context.Provider>;
41
- },
42
- );
@@ -1,74 +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
- activationKeys: [],
38
- excluded: [],
39
- },
40
- pinch: {
41
- step: 5,
42
- disabled: false,
43
- excluded: [],
44
- },
45
- doubleClick: {
46
- disabled: false,
47
- step: 0.7,
48
- mode: "zoomIn",
49
- animationType: "easeOut",
50
- animationTime: 200,
51
- excluded: [],
52
- },
53
- zoomAnimation: {
54
- disabled: false,
55
- size: 0.4,
56
- animationTime: 200,
57
- animationType: "easeOut",
58
- },
59
- alignmentAnimation: {
60
- disabled: false,
61
- sizeX: 100,
62
- sizeY: 100,
63
- animationTime: 200,
64
- velocityAlignmentTime: 400,
65
- animationType: "easeOut",
66
- },
67
- velocityAnimation: {
68
- disabled: false,
69
- sensitivity: 1,
70
- animationTime: 400,
71
- animationType: "easeOut",
72
- equalToMove: true,
73
- },
74
- };
@@ -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
- }
@@ -1,8 +0,0 @@
1
- export type ComponentsSizesType = {
2
- wrapperWidth: number;
3
- wrapperHeight: number;
4
- newContentWidth: number;
5
- newDiffWidth: number;
6
- newContentHeight: number;
7
- newDiffHeight: number;
8
- };