react-zoom-pan-pinch 4.0.6 → 4.1.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 +6 -1
- package/dist/index.cjs.js +486 -132
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +68 -7
- package/dist/index.esm.js +487 -134
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/keep-scale/keep-scale.tsx +13 -4
- package/src/components/mini-map/mini-map.tsx +10 -21
- package/src/components/transform-component/transform-component.tsx +8 -1
- package/src/components/transform-wrapper/transform-wrapper.tsx +14 -1
- package/src/components/virtualize/virtualize.tsx +32 -19
- package/src/core/animations/animations.utils.ts +50 -18
- package/src/core/double-click/double-click.logic.ts +5 -0
- package/src/core/handlers/handlers.logic.ts +160 -28
- package/src/core/handlers/handlers.utils.ts +182 -55
- package/src/core/instance.core.ts +51 -3
- package/src/core/pan/panning.logic.ts +10 -1
- package/src/core/pan/panning.utils.ts +6 -6
- package/src/core/wheel/wheel.logic.ts +13 -2
- package/src/core/wheel/wheel.utils.ts +4 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-transform-component.tsx +1 -1
- package/src/hooks/use-zoom-pan-pinch.tsx +9 -3
- package/src/models/context.model.ts +21 -0
- package/src/utils/context.utils.ts +6 -0
- package/src/utils/effect.utils.ts +11 -0
- package/src/utils/helpers.utils.ts +37 -0
- package/src/utils/index.ts +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -23,12 +23,39 @@ type DeepNonNullableObject<T> = {
|
|
|
23
23
|
[P in keyof T]-?: DeepNonNullable<NonNullable<T[P]>>;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
declare const zoomIn: (contextInstance: ReactZoomPanPinchContext) => (step?: number, animationTime?: number, animationType?: keyof typeof animations) => void
|
|
27
|
-
declare const zoomOut: (contextInstance: ReactZoomPanPinchContext) => (step?: number, animationTime?: number, animationType?: keyof typeof animations) => void
|
|
28
|
-
declare const setTransform: (contextInstance: ReactZoomPanPinchContext) => (newPositionX: number, newPositionY: number, newScale: number, animationTime?: number, animationType?: keyof typeof animations) => void
|
|
29
|
-
declare const resetTransform: (contextInstance: ReactZoomPanPinchContext) => (animationTime?: number, animationType?: keyof typeof animations) => void
|
|
30
|
-
declare const centerView: (contextInstance: ReactZoomPanPinchContext) => (scale?: number, animationTime?: number, animationType?: keyof typeof animations) => void
|
|
31
|
-
|
|
26
|
+
declare const zoomIn: (contextInstance: ReactZoomPanPinchContext) => (step?: number, animationTime?: number, animationType?: keyof typeof animations) => Promise<void>;
|
|
27
|
+
declare const zoomOut: (contextInstance: ReactZoomPanPinchContext) => (step?: number, animationTime?: number, animationType?: keyof typeof animations) => Promise<void>;
|
|
28
|
+
declare const setTransform: (contextInstance: ReactZoomPanPinchContext) => (newPositionX: number, newPositionY: number, newScale: number, animationTime?: number, animationType?: keyof typeof animations) => Promise<void>;
|
|
29
|
+
declare const resetTransform: (contextInstance: ReactZoomPanPinchContext) => (animationTime?: number, animationType?: keyof typeof animations) => Promise<void>;
|
|
30
|
+
declare const centerView: (contextInstance: ReactZoomPanPinchContext) => (scale?: number, animationTime?: number, animationType?: keyof typeof animations) => Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Zooms so that the content point currently under the client (viewport)
|
|
33
|
+
* coordinates `clientX`/`clientY` stays fixed on screen — the same anchoring a
|
|
34
|
+
* wheel zoom does at the cursor. Useful for click-to-zoom and focal zooms
|
|
35
|
+
* (#353).
|
|
36
|
+
*/
|
|
37
|
+
declare const zoomToPoint: (contextInstance: ReactZoomPanPinchContext) => (scale: number, clientX: number, clientY: number, animationTime?: number, animationType?: keyof typeof animations) => Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Converts client (viewport) coordinates — e.g. `event.clientX/Y` — into
|
|
40
|
+
* content coordinates: the unscaled position inside `TransformComponent`
|
|
41
|
+
* regardless of the current pan and zoom (#378).
|
|
42
|
+
*/
|
|
43
|
+
declare const clientToContent: (contextInstance: ReactZoomPanPinchContext) => (clientX: number, clientY: number) => PositionType;
|
|
44
|
+
/**
|
|
45
|
+
* Inverse of `clientToContent`: converts unscaled content coordinates into
|
|
46
|
+
* client (viewport) coordinates for the current transform.
|
|
47
|
+
*/
|
|
48
|
+
declare const contentToClient: (contextInstance: ReactZoomPanPinchContext) => (x: number, y: number) => PositionType;
|
|
49
|
+
/**
|
|
50
|
+
* Zooms and pans so the target element(s) fill the viewport.
|
|
51
|
+
*
|
|
52
|
+
* - `node` may be an element, an element id, or an array of either; with
|
|
53
|
+
* several targets the union of their boxes is framed (#388).
|
|
54
|
+
* - The second argument is either the target `scale` (legacy positional
|
|
55
|
+
* form) or an options object. `minScale`/`maxScale` cap the automatically
|
|
56
|
+
* computed fit scale (#515).
|
|
57
|
+
*/
|
|
58
|
+
declare const zoomToElement: (contextInstance: ReactZoomPanPinchContext) => (node: ZoomToElementTarget | ZoomToElementTarget[], scaleOrOptions?: number | ZoomToElementOptions, animationTime?: number, animationType?: keyof typeof animations, offsetX?: number, offsetY?: number) => Promise<void>;
|
|
32
59
|
|
|
33
60
|
type StartCoordsType = {
|
|
34
61
|
x: number;
|
|
@@ -77,6 +104,9 @@ declare class ZoomPanPinch {
|
|
|
77
104
|
lastMousePosition: PositionType | null;
|
|
78
105
|
isAnimating: boolean;
|
|
79
106
|
animation: AnimationType | null;
|
|
107
|
+
animationFrame: number | null;
|
|
108
|
+
animationResolve: (() => void) | null;
|
|
109
|
+
initObserverTimer: ReturnType<typeof setTimeout> | null;
|
|
80
110
|
pressedKeys: {
|
|
81
111
|
[key: string]: boolean;
|
|
82
112
|
};
|
|
@@ -84,8 +114,10 @@ declare class ZoomPanPinch {
|
|
|
84
114
|
mount: () => void;
|
|
85
115
|
unmount: () => void;
|
|
86
116
|
update: (newProps: ReactZoomPanPinchProps) => void;
|
|
117
|
+
clearTimers: () => void;
|
|
87
118
|
initializeWindowEvents: () => void;
|
|
88
119
|
cleanupWindowEvents: () => void;
|
|
120
|
+
cleanupWrapperEvents: () => void;
|
|
89
121
|
handleInitializeWrapperEvents: (wrapper: HTMLDivElement) => void;
|
|
90
122
|
handleInitialize: (contentComponent: HTMLDivElement) => void;
|
|
91
123
|
onWheelZoom: (event: WheelEvent) => void;
|
|
@@ -129,6 +161,19 @@ declare class ZoomPanPinch {
|
|
|
129
161
|
init: (wrapperComponent: HTMLDivElement, contentComponent: HTMLDivElement) => void;
|
|
130
162
|
}
|
|
131
163
|
|
|
164
|
+
type ZoomToElementTarget = HTMLElement | string;
|
|
165
|
+
type ZoomToElementOptions = {
|
|
166
|
+
/** Explicit target scale; when omitted the element(s) are fitted to the viewport. */
|
|
167
|
+
scale?: number;
|
|
168
|
+
/** Lower cap for the automatically computed fit scale. */
|
|
169
|
+
minScale?: number;
|
|
170
|
+
/** Upper cap for the automatically computed fit scale (e.g. stop tiny elements from over-zooming). */
|
|
171
|
+
maxScale?: number;
|
|
172
|
+
animationTime?: number;
|
|
173
|
+
animationType?: keyof typeof animations;
|
|
174
|
+
offsetX?: number;
|
|
175
|
+
offsetY?: number;
|
|
176
|
+
};
|
|
132
177
|
type ReactZoomPanPinchContext = typeof ZoomPanPinch.prototype;
|
|
133
178
|
type ReactZoomPanPinchContextState = {
|
|
134
179
|
instance: ReactZoomPanPinchContext;
|
|
@@ -152,6 +197,9 @@ type ReactZoomPanPinchHandlers = {
|
|
|
152
197
|
resetTransform: ReturnType<typeof resetTransform>;
|
|
153
198
|
centerView: ReturnType<typeof centerView>;
|
|
154
199
|
zoomToElement: ReturnType<typeof zoomToElement>;
|
|
200
|
+
zoomToPoint: ReturnType<typeof zoomToPoint>;
|
|
201
|
+
clientToContent: ReturnType<typeof clientToContent>;
|
|
202
|
+
contentToClient: ReturnType<typeof contentToClient>;
|
|
155
203
|
};
|
|
156
204
|
type ReactZoomPanPinchRefProps = {
|
|
157
205
|
setRef: (context: ReactZoomPanPinchRef) => void;
|
|
@@ -313,6 +361,19 @@ declare const useTransformContext: () => ZoomPanPinch;
|
|
|
313
361
|
|
|
314
362
|
declare function useTransformComponent<T>(callback: (state: ReactZoomPanPinchContextState) => T): T;
|
|
315
363
|
|
|
364
|
+
declare const useZoomPanPinch: (props?: ReactZoomPanPinchProps) => {
|
|
365
|
+
contentRef: React.RefObject<HTMLDivElement>;
|
|
366
|
+
wrapperRef: React.RefObject<HTMLDivElement>;
|
|
367
|
+
instance: React.MutableRefObject<ZoomPanPinch>;
|
|
368
|
+
useTransform: (callback: (data: {
|
|
369
|
+
positionX: number;
|
|
370
|
+
positionY: number;
|
|
371
|
+
scale: number;
|
|
372
|
+
previousScale: number;
|
|
373
|
+
ref: ReactZoomPanPinchRef;
|
|
374
|
+
}) => void) => void;
|
|
375
|
+
};
|
|
376
|
+
|
|
316
377
|
declare const KeepScale: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
317
378
|
|
|
318
379
|
type MiniMapProps = {
|
|
@@ -396,4 +457,4 @@ declare const getTransformStyles: (x: number, y: number, scale: number) => strin
|
|
|
396
457
|
declare const getMatrixTransformStyles: (x: number, y: number, scale: number) => string;
|
|
397
458
|
declare const getCenterPosition: (scale: number, wrapperComponent: HTMLDivElement, contentComponent: HTMLDivElement) => StateType;
|
|
398
459
|
|
|
399
|
-
export { type AnimationType, type BoundsType, Context, DeviceType, KeepScale, type LibrarySetup, MiniMap, type MiniMapProps, type PositionType, type ReactZoomPanPinchBaseClasses, type ReactZoomPanPinchComponentHelpers, type ReactZoomPanPinchContentRef, type ReactZoomPanPinchContext, type ReactZoomPanPinchContextState, type ReactZoomPanPinchHandlers, type ReactZoomPanPinchProps, type ReactZoomPanPinchRef, type ReactZoomPanPinchRefProps, type ReactZoomPanPinchState, type SizeType, type StateType, TransformComponent, TransformWrapper, type VelocityType, Virtualize, type VirtualizeProps, getCenterPosition, getMatrixTransformStyles, getTransformStyles, roundScaleForTransform, useControls, useTransformComponent, useTransformContext, useTransformEffect, useTransformInit };
|
|
460
|
+
export { type AnimationType, type BoundsType, Context, DeviceType, KeepScale, type LibrarySetup, MiniMap, type MiniMapProps, type PositionType, type ReactZoomPanPinchBaseClasses, type ReactZoomPanPinchComponentHelpers, type ReactZoomPanPinchContentRef, type ReactZoomPanPinchContext, type ReactZoomPanPinchContextState, type ReactZoomPanPinchHandlers, type ReactZoomPanPinchProps, type ReactZoomPanPinchRef, type ReactZoomPanPinchRefProps, type ReactZoomPanPinchState, type SizeType, type StateType, TransformComponent, TransformWrapper, type VelocityType, Virtualize, type VirtualizeProps, type ZoomToElementOptions, type ZoomToElementTarget, getCenterPosition, getMatrixTransformStyles, getTransformStyles, roundScaleForTransform, useControls, useTransformComponent, useTransformContext, useTransformEffect, useTransformInit, useZoomPanPinch };
|