react-zoom-pan-pinch 4.1.0 → 4.2.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/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: (contentComponent: HTMLDivElement) => void;
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;
@@ -457,4 +522,4 @@ declare const getTransformStyles: (x: number, y: number, scale: number) => strin
457
522
  declare const getMatrixTransformStyles: (x: number, y: number, scale: number) => string;
458
523
  declare const getCenterPosition: (scale: number, wrapperComponent: HTMLDivElement, contentComponent: HTMLDivElement) => StateType;
459
524
 
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 };
525
+ 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 };