react-zoom-pan-pinch 4.0.7 → 4.1.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/README.md +6 -1
- package/dist/index.cjs.js +290 -72
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +64 -7
- package/dist/index.esm.js +290 -73
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/transform-component/transform-component.tsx +3 -0
- package/src/core/animations/animations.utils.ts +34 -5
- package/src/core/handlers/handlers.logic.ts +160 -36
- package/src/core/handlers/handlers.utils.ts +177 -51
- package/src/core/instance.core.ts +2 -0
- package/src/core/pan/panning.logic.ts +10 -1
- package/src/core/wheel/wheel.logic.ts +10 -2
- package/src/hooks/index.ts +1 -0
- package/src/models/context.model.ts +21 -0
- package/src/utils/context.utils.ts +6 -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;
|
|
@@ -78,6 +105,7 @@ declare class ZoomPanPinch {
|
|
|
78
105
|
isAnimating: boolean;
|
|
79
106
|
animation: AnimationType | null;
|
|
80
107
|
animationFrame: number | null;
|
|
108
|
+
animationResolve: (() => void) | null;
|
|
81
109
|
initObserverTimer: ReturnType<typeof setTimeout> | null;
|
|
82
110
|
pressedKeys: {
|
|
83
111
|
[key: string]: boolean;
|
|
@@ -133,6 +161,19 @@ declare class ZoomPanPinch {
|
|
|
133
161
|
init: (wrapperComponent: HTMLDivElement, contentComponent: HTMLDivElement) => void;
|
|
134
162
|
}
|
|
135
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
|
+
};
|
|
136
177
|
type ReactZoomPanPinchContext = typeof ZoomPanPinch.prototype;
|
|
137
178
|
type ReactZoomPanPinchContextState = {
|
|
138
179
|
instance: ReactZoomPanPinchContext;
|
|
@@ -156,6 +197,9 @@ type ReactZoomPanPinchHandlers = {
|
|
|
156
197
|
resetTransform: ReturnType<typeof resetTransform>;
|
|
157
198
|
centerView: ReturnType<typeof centerView>;
|
|
158
199
|
zoomToElement: ReturnType<typeof zoomToElement>;
|
|
200
|
+
zoomToPoint: ReturnType<typeof zoomToPoint>;
|
|
201
|
+
clientToContent: ReturnType<typeof clientToContent>;
|
|
202
|
+
contentToClient: ReturnType<typeof contentToClient>;
|
|
159
203
|
};
|
|
160
204
|
type ReactZoomPanPinchRefProps = {
|
|
161
205
|
setRef: (context: ReactZoomPanPinchRef) => void;
|
|
@@ -317,6 +361,19 @@ declare const useTransformContext: () => ZoomPanPinch;
|
|
|
317
361
|
|
|
318
362
|
declare function useTransformComponent<T>(callback: (state: ReactZoomPanPinchContextState) => T): T;
|
|
319
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
|
+
|
|
320
377
|
declare const KeepScale: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
321
378
|
|
|
322
379
|
type MiniMapProps = {
|
|
@@ -400,4 +457,4 @@ declare const getTransformStyles: (x: number, y: number, scale: number) => strin
|
|
|
400
457
|
declare const getMatrixTransformStyles: (x: number, y: number, scale: number) => string;
|
|
401
458
|
declare const getCenterPosition: (scale: number, wrapperComponent: HTMLDivElement, contentComponent: HTMLDivElement) => StateType;
|
|
402
459
|
|
|
403
|
-
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 };
|