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
package/dist/index.d.ts
CHANGED
|
@@ -56,6 +56,25 @@ declare const contentToClient: (contextInstance: ReactZoomPanPinchContext) => (x
|
|
|
56
56
|
* computed fit scale (#515).
|
|
57
57
|
*/
|
|
58
58
|
declare const zoomToElement: (contextInstance: ReactZoomPanPinchContext) => (node: ZoomToElementTarget | ZoomToElementTarget[], scaleOrOptions?: number | ZoomToElementOptions, animationTime?: number, animationType?: keyof typeof animations, offsetX?: number, offsetY?: number) => Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Fits the whole content into the viewport (`contain`, default) or fills the
|
|
61
|
+
* viewport with it (`cover`), centred. Honours the wrapper's
|
|
62
|
+
* `minScale`/`maxScale`; lower `minScale` to let large content shrink (#252).
|
|
63
|
+
*/
|
|
64
|
+
declare const fitToView: (contextInstance: ReactZoomPanPinchContext) => (options?: FitToViewOptions) => Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Pans by a pixel delta (positive x moves the content right), limited to the
|
|
67
|
+
* bounds when `limitToBounds` is on. Backs the keyboard arrows and is handy
|
|
68
|
+
* for directional buttons (#254, #527).
|
|
69
|
+
*/
|
|
70
|
+
declare const panBy: (contextInstance: ReactZoomPanPinchContext) => (deltaX: number, deltaY: number, animationTime?: number, animationType?: keyof typeof animations) => Promise<void>;
|
|
71
|
+
|
|
72
|
+
type MeasuredSizesType = {
|
|
73
|
+
wrapperWidth: number;
|
|
74
|
+
wrapperHeight: number;
|
|
75
|
+
contentWidth: number;
|
|
76
|
+
contentHeight: number;
|
|
77
|
+
};
|
|
59
78
|
|
|
60
79
|
type StartCoordsType = {
|
|
61
80
|
x: number;
|
|
@@ -107,9 +126,17 @@ declare class ZoomPanPinch {
|
|
|
107
126
|
animationFrame: number | null;
|
|
108
127
|
animationResolve: (() => void) | null;
|
|
109
128
|
initObserverTimer: ReturnType<typeof setTimeout> | null;
|
|
129
|
+
isInitialLayoutPending: boolean;
|
|
130
|
+
measuredSizes: MeasuredSizesType | null;
|
|
131
|
+
isResizeAlignmentPending: boolean;
|
|
132
|
+
resizeAnimation: AnimationType | null;
|
|
110
133
|
pressedKeys: {
|
|
111
134
|
[key: string]: boolean;
|
|
112
135
|
};
|
|
136
|
+
selectionLock: {
|
|
137
|
+
userSelect: string;
|
|
138
|
+
webkitUserSelect: string;
|
|
139
|
+
} | null;
|
|
113
140
|
constructor(props: ReactZoomPanPinchProps);
|
|
114
141
|
mount: () => void;
|
|
115
142
|
unmount: () => void;
|
|
@@ -119,7 +146,10 @@ declare class ZoomPanPinch {
|
|
|
119
146
|
cleanupWindowEvents: () => void;
|
|
120
147
|
cleanupWrapperEvents: () => void;
|
|
121
148
|
handleInitializeWrapperEvents: (wrapper: HTMLDivElement) => void;
|
|
122
|
-
handleInitialize: (
|
|
149
|
+
handleInitialize: () => void;
|
|
150
|
+
observeSizes: (wrapperComponent: HTMLDivElement, contentComponent: HTMLDivElement) => void;
|
|
151
|
+
onSizeChange: () => void;
|
|
152
|
+
flushResizeAlignment: () => void;
|
|
123
153
|
onWheelZoom: (event: WheelEvent) => void;
|
|
124
154
|
onWheelPanning: (event: WheelEvent) => void;
|
|
125
155
|
onPanningStart: (event: MouseEvent) => void;
|
|
@@ -138,6 +168,11 @@ declare class ZoomPanPinch {
|
|
|
138
168
|
setKeyPressed: (e: KeyboardEvent) => void;
|
|
139
169
|
setKeyUnPressed: (e: KeyboardEvent) => void;
|
|
140
170
|
isPressingKeys: (keys: string[] | ((keys: string[]) => boolean)) => boolean;
|
|
171
|
+
onKeyboardNavigation: (event: KeyboardEvent) => void;
|
|
172
|
+
focusForKeyboard: () => void;
|
|
173
|
+
lockTextSelection: () => void;
|
|
174
|
+
unlockTextSelection: () => void;
|
|
175
|
+
applyInitialLayout: () => boolean;
|
|
141
176
|
setCenter: () => void;
|
|
142
177
|
handleTransformStyles: (x: number, y: number, scale: number) => string;
|
|
143
178
|
getContext: () => ReactZoomPanPinchRef;
|
|
@@ -174,6 +209,17 @@ type ZoomToElementOptions = {
|
|
|
174
209
|
offsetX?: number;
|
|
175
210
|
offsetY?: number;
|
|
176
211
|
};
|
|
212
|
+
type FitToViewMode = "contain" | "cover";
|
|
213
|
+
type FitToViewOptions = {
|
|
214
|
+
/** `contain` (default) shows the whole content, `cover` fills the viewport. */
|
|
215
|
+
mode?: FitToViewMode;
|
|
216
|
+
/** Lower cap for the computed fit scale. */
|
|
217
|
+
minScale?: number;
|
|
218
|
+
/** Upper cap for the computed fit scale. */
|
|
219
|
+
maxScale?: number;
|
|
220
|
+
animationTime?: number;
|
|
221
|
+
animationType?: keyof typeof animations;
|
|
222
|
+
};
|
|
177
223
|
type ReactZoomPanPinchContext = typeof ZoomPanPinch.prototype;
|
|
178
224
|
type ReactZoomPanPinchContextState = {
|
|
179
225
|
instance: ReactZoomPanPinchContext;
|
|
@@ -200,6 +246,8 @@ type ReactZoomPanPinchHandlers = {
|
|
|
200
246
|
zoomToPoint: ReturnType<typeof zoomToPoint>;
|
|
201
247
|
clientToContent: ReturnType<typeof clientToContent>;
|
|
202
248
|
contentToClient: ReturnType<typeof contentToClient>;
|
|
249
|
+
fitToView: ReturnType<typeof fitToView>;
|
|
250
|
+
panBy: ReturnType<typeof panBy>;
|
|
203
251
|
};
|
|
204
252
|
type ReactZoomPanPinchRefProps = {
|
|
205
253
|
setRef: (context: ReactZoomPanPinchRef) => void;
|
|
@@ -221,6 +269,12 @@ type ReactZoomPanPinchProps = {
|
|
|
221
269
|
limitToBounds?: boolean;
|
|
222
270
|
centerZoomedOut?: boolean;
|
|
223
271
|
centerOnInit?: boolean;
|
|
272
|
+
/**
|
|
273
|
+
* Fit the content to the wrapper on init (and again when the content gets
|
|
274
|
+
* its size, e.g. after an image loads). `true`/`"contain"` shows the whole
|
|
275
|
+
* content, `"cover"` fills the wrapper. Honours `minScale`/`maxScale`.
|
|
276
|
+
*/
|
|
277
|
+
fitOnInit?: boolean | FitToViewMode;
|
|
224
278
|
disablePadding?: boolean;
|
|
225
279
|
customTransform?: (x: number, y: number, scale: number) => string;
|
|
226
280
|
smooth?: boolean;
|
|
@@ -257,6 +311,17 @@ type ReactZoomPanPinchProps = {
|
|
|
257
311
|
activationKeys?: string[] | ((keys: string[]) => boolean);
|
|
258
312
|
excluded?: string[];
|
|
259
313
|
};
|
|
314
|
+
keyboard?: {
|
|
315
|
+
/** Keyboard navigation is opt-in. */
|
|
316
|
+
disabled?: boolean;
|
|
317
|
+
/** Pixels moved per arrow key press. */
|
|
318
|
+
panStep?: number;
|
|
319
|
+
/** Scale added/removed per +/- press. */
|
|
320
|
+
zoomStep?: number;
|
|
321
|
+
animationTime?: number;
|
|
322
|
+
animationType?: keyof typeof animations;
|
|
323
|
+
excluded?: string[];
|
|
324
|
+
};
|
|
260
325
|
doubleClick?: {
|
|
261
326
|
disabled?: boolean;
|
|
262
327
|
step?: number;
|
|
@@ -378,17 +443,48 @@ declare const KeepScale: React.ForwardRefExoticComponent<React.HTMLAttributes<HT
|
|
|
378
443
|
|
|
379
444
|
type MiniMapProps = {
|
|
380
445
|
children: React.ReactNode;
|
|
446
|
+
/** Width of the mini map box in px. */
|
|
381
447
|
width?: number;
|
|
448
|
+
/** Height of the mini map box in px. */
|
|
382
449
|
height?: number;
|
|
450
|
+
/** Border colour of the viewport indicator. */
|
|
383
451
|
borderColor?: string;
|
|
452
|
+
/**
|
|
453
|
+
* Colour of the overlay that dims everything outside the viewport
|
|
454
|
+
* (`.rzpp-minimap-mask`).
|
|
455
|
+
*/
|
|
456
|
+
maskColor?: string;
|
|
384
457
|
/** Merged onto the viewport indicator (`.rzpp-minimap-preview`). */
|
|
385
458
|
previewStyle?: React.CSSProperties;
|
|
386
459
|
/** Extra class name(s) appended to `.rzpp-minimap-wrapper`. */
|
|
387
460
|
wrapperClassName?: string;
|
|
388
461
|
/** Extra class name(s) appended to `.rzpp-minimap-preview`. */
|
|
389
462
|
previewClassName?: string;
|
|
463
|
+
/**
|
|
464
|
+
* Dragging anywhere on the mini map grabs the viewport indicator and moves
|
|
465
|
+
* it with the pointer (mouse and touch).
|
|
466
|
+
*/
|
|
390
467
|
panning?: boolean;
|
|
391
|
-
|
|
468
|
+
/**
|
|
469
|
+
* Flips the drag direction: instead of grabbing the viewport indicator the
|
|
470
|
+
* drag moves the content, like panning the main view.
|
|
471
|
+
*/
|
|
472
|
+
inversePan?: boolean;
|
|
473
|
+
/** Wheel over the mini map zooms the main view around its centre. */
|
|
474
|
+
zoomable?: boolean;
|
|
475
|
+
/** Scale increment applied per wheel notch when `zoomable` is on. */
|
|
476
|
+
zoomStep?: number;
|
|
477
|
+
/**
|
|
478
|
+
* Padding around the mapped area, in mini map px at the current map scale
|
|
479
|
+
* (same meaning as React Flow's `offsetScale`).
|
|
480
|
+
*/
|
|
481
|
+
offsetScale?: number;
|
|
482
|
+
/**
|
|
483
|
+
* Fired for a click (or tap) that did not turn into a drag. `position` is
|
|
484
|
+
* the clicked point in content coordinates, ready for `zoomToPoint`.
|
|
485
|
+
*/
|
|
486
|
+
onClick?: (event: MouseEvent | TouchEvent, position: PositionType) => void;
|
|
487
|
+
} & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "onClick">;
|
|
392
488
|
declare const MiniMap: React.FC<MiniMapProps>;
|
|
393
489
|
|
|
394
490
|
type Props = {
|
|
@@ -457,4 +553,4 @@ declare const getTransformStyles: (x: number, y: number, scale: number) => strin
|
|
|
457
553
|
declare const getMatrixTransformStyles: (x: number, y: number, scale: number) => string;
|
|
458
554
|
declare const getCenterPosition: (scale: number, wrapperComponent: HTMLDivElement, contentComponent: HTMLDivElement) => StateType;
|
|
459
555
|
|
|
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 };
|
|
556
|
+
export { type AnimationType, type BoundsType, Context, DeviceType, type FitToViewMode, type FitToViewOptions, 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 };
|