react-zoom-pan-pinch 4.1.1 → 4.3.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/README.md +4 -4
- package/dist/index.cjs.js +1081 -231
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +99 -3
- package/dist/index.esm.js +1082 -232
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/mini-map/mini-map.tsx +386 -171
- package/src/components/transform-component/transform-component.module.css +2 -5
- package/src/components/transform-component/transform-component.tsx +7 -0
- package/src/components/virtualize/virtualize.tsx +2 -2
- package/src/constants/state.constants.ts +9 -0
- package/src/core/animations/animations.utils.ts +2 -0
- package/src/core/bounds/bounds.utils.ts +90 -2
- package/src/core/handlers/handlers.logic.ts +85 -0
- package/src/core/handlers/handlers.utils.ts +102 -5
- package/src/core/instance.core.ts +222 -41
- package/src/core/keyboard/keyboard.logic.ts +84 -0
- package/src/core/pan/panning.logic.ts +24 -4
- package/src/core/pan/panning.utils.ts +95 -36
- package/src/core/pan/velocity.logic.ts +11 -4
- package/src/core/pan/velocity.utils.ts +2 -2
- package/src/core/resize/index.ts +0 -0
- package/src/core/resize/resize.logic.ts +245 -0
- package/src/core/resize/resize.types.ts +6 -0
- package/src/core/wheel/wheel.logic.ts +11 -2
- package/src/core/zoom/zoom.logic.ts +2 -2
- package/src/hooks/initial-layout.utils.ts +21 -0
- package/src/hooks/use-transform-component.tsx +22 -4
- package/src/hooks/use-transform-effect.tsx +20 -1
- package/src/models/context.model.ts +34 -0
- package/src/utils/context.utils.ts +4 -0
- package/src/utils/styles.utils.ts +2 -2
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
centerView,
|
|
7
7
|
clientToContent,
|
|
8
8
|
contentToClient,
|
|
9
|
+
fitToView,
|
|
10
|
+
panBy,
|
|
9
11
|
resetTransform,
|
|
10
12
|
setTransform,
|
|
11
13
|
zoomIn,
|
|
@@ -30,6 +32,19 @@ export type ZoomToElementOptions = {
|
|
|
30
32
|
offsetY?: number;
|
|
31
33
|
};
|
|
32
34
|
|
|
35
|
+
export type FitToViewMode = "contain" | "cover";
|
|
36
|
+
|
|
37
|
+
export type FitToViewOptions = {
|
|
38
|
+
/** `contain` (default) shows the whole content, `cover` fills the viewport. */
|
|
39
|
+
mode?: FitToViewMode;
|
|
40
|
+
/** Lower cap for the computed fit scale. */
|
|
41
|
+
minScale?: number;
|
|
42
|
+
/** Upper cap for the computed fit scale. */
|
|
43
|
+
maxScale?: number;
|
|
44
|
+
animationTime?: number;
|
|
45
|
+
animationType?: keyof typeof animations;
|
|
46
|
+
};
|
|
47
|
+
|
|
33
48
|
export type ReactZoomPanPinchContext = typeof ZoomPanPinch.prototype;
|
|
34
49
|
|
|
35
50
|
export type ReactZoomPanPinchContextState = {
|
|
@@ -62,6 +77,8 @@ export type ReactZoomPanPinchHandlers = {
|
|
|
62
77
|
zoomToPoint: ReturnType<typeof zoomToPoint>;
|
|
63
78
|
clientToContent: ReturnType<typeof clientToContent>;
|
|
64
79
|
contentToClient: ReturnType<typeof contentToClient>;
|
|
80
|
+
fitToView: ReturnType<typeof fitToView>;
|
|
81
|
+
panBy: ReturnType<typeof panBy>;
|
|
65
82
|
};
|
|
66
83
|
|
|
67
84
|
export type ReactZoomPanPinchRefProps = {
|
|
@@ -87,6 +104,12 @@ export type ReactZoomPanPinchProps = {
|
|
|
87
104
|
limitToBounds?: boolean;
|
|
88
105
|
centerZoomedOut?: boolean;
|
|
89
106
|
centerOnInit?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Fit the content to the wrapper on init (and again when the content gets
|
|
109
|
+
* its size, e.g. after an image loads). `true`/`"contain"` shows the whole
|
|
110
|
+
* content, `"cover"` fills the wrapper. Honours `minScale`/`maxScale`.
|
|
111
|
+
*/
|
|
112
|
+
fitOnInit?: boolean | FitToViewMode;
|
|
90
113
|
disablePadding?: boolean;
|
|
91
114
|
customTransform?: (x: number, y: number, scale: number) => string;
|
|
92
115
|
smooth?: boolean;
|
|
@@ -123,6 +146,17 @@ export type ReactZoomPanPinchProps = {
|
|
|
123
146
|
activationKeys?: string[] | ((keys: string[]) => boolean);
|
|
124
147
|
excluded?: string[];
|
|
125
148
|
};
|
|
149
|
+
keyboard?: {
|
|
150
|
+
/** Keyboard navigation is opt-in. */
|
|
151
|
+
disabled?: boolean;
|
|
152
|
+
/** Pixels moved per arrow key press. */
|
|
153
|
+
panStep?: number;
|
|
154
|
+
/** Scale added/removed per +/- press. */
|
|
155
|
+
zoomStep?: number;
|
|
156
|
+
animationTime?: number;
|
|
157
|
+
animationType?: keyof typeof animations;
|
|
158
|
+
excluded?: string[];
|
|
159
|
+
};
|
|
126
160
|
doubleClick?: {
|
|
127
161
|
disabled?: boolean;
|
|
128
162
|
step?: number;
|
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
centerView,
|
|
15
15
|
clientToContent,
|
|
16
16
|
contentToClient,
|
|
17
|
+
fitToView,
|
|
18
|
+
panBy,
|
|
17
19
|
} from "../core/handlers/handlers.logic";
|
|
18
20
|
|
|
19
21
|
export const getControls = (
|
|
@@ -31,6 +33,8 @@ export const getControls = (
|
|
|
31
33
|
zoomToPoint: zoomToPoint(contextInstance),
|
|
32
34
|
clientToContent: clientToContent(contextInstance),
|
|
33
35
|
contentToClient: contentToClient(contextInstance),
|
|
36
|
+
fitToView: fitToView(contextInstance),
|
|
37
|
+
panBy: panBy(contextInstance),
|
|
34
38
|
};
|
|
35
39
|
};
|
|
36
40
|
|
|
@@ -38,8 +38,8 @@ export const getCenterPosition = (
|
|
|
38
38
|
const contentWidth = contentComponent.offsetWidth * scale;
|
|
39
39
|
const contentHeight = contentComponent.offsetHeight * scale;
|
|
40
40
|
|
|
41
|
-
const centerPositionX = (wrapperComponent.
|
|
42
|
-
const centerPositionY = (wrapperComponent.
|
|
41
|
+
const centerPositionX = (wrapperComponent.clientWidth - contentWidth) / 2;
|
|
42
|
+
const centerPositionY = (wrapperComponent.clientHeight - contentHeight) / 2;
|
|
43
43
|
|
|
44
44
|
return {
|
|
45
45
|
scale,
|