react-zoom-pan-pinch 3.0.8 → 3.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.
@@ -47,8 +47,10 @@ export type ReactZoomPanPinchProps = {
47
47
  centerOnInit?: boolean;
48
48
  disablePadding?: boolean;
49
49
  customTransform?: (x: number, y: number, scale: number) => string;
50
+ smooth?: boolean;
50
51
  wheel?: {
51
52
  step?: number;
53
+ smoothStep?: number;
52
54
  disabled?: boolean;
53
55
  wheelDisabled?: boolean;
54
56
  touchPadDisabled?: boolean;
@@ -16,6 +16,18 @@ export declare const argsTypes: {
16
16
  };
17
17
  };
18
18
  };
19
+ "wheel.smoothStep": {
20
+ defaultValue: number;
21
+ control: {
22
+ type: string;
23
+ min: number;
24
+ };
25
+ table: {
26
+ defaultValue: {
27
+ summary: string;
28
+ };
29
+ };
30
+ };
19
31
  "wheel.disabled": {
20
32
  defaultValue: NonNullable<boolean | undefined>;
21
33
  control: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-zoom-pan-pinch",
3
- "version": "3.0.8",
3
+ "version": "3.1.1",
4
4
  "description": "Zoom and pan html elements in easy way",
5
5
  "author": "prc5",
6
6
  "license": "MIT",
@@ -32,6 +32,9 @@ export const TransformWrapper = React.forwardRef(
32
32
 
33
33
  useEffect(() => {
34
34
  instance.update(props);
35
+ return () => {
36
+ instance.cleanupWindowEvents();
37
+ };
35
38
  }, [instance, props]);
36
39
 
37
40
  return <Context.Provider value={instance}>{content}</Context.Provider>;
@@ -19,9 +19,11 @@ export const initialSetup: LibrarySetup = {
19
19
  centerZoomedOut: false,
20
20
  centerOnInit: false,
21
21
  disablePadding: false,
22
+ smooth: true,
22
23
  wheel: {
23
24
  step: 0.2,
24
25
  disabled: false,
26
+ smoothStep: 0.001,
25
27
  wheelDisabled: false,
26
28
  touchPadDisabled: false,
27
29
  activationKeys: [],
@@ -17,14 +17,16 @@ export const handleCalculateButtonZoom = (
17
17
  ): number => {
18
18
  const { scale } = contextInstance.transformState;
19
19
  const { wrapperComponent, setup } = contextInstance;
20
- const { maxScale, minScale, zoomAnimation } = setup;
20
+ const { maxScale, minScale, zoomAnimation, smooth } = setup;
21
21
  const { size } = zoomAnimation;
22
22
 
23
23
  if (!wrapperComponent) {
24
24
  throw new Error("Wrapper is not mounted");
25
25
  }
26
26
 
27
- const targetScale = scale + delta * step;
27
+ const targetScale = smooth
28
+ ? scale * Math.exp(delta * step)
29
+ : scale + delta * step;
28
30
 
29
31
  const newScale = checkZoomBounds(
30
32
  roundNumber(targetScale, 3),
@@ -44,9 +44,10 @@ export const handleWheelZoom = (
44
44
  zoomAnimation,
45
45
  wheel,
46
46
  disablePadding,
47
+ smooth,
47
48
  } = setup;
48
49
  const { size, disabled } = zoomAnimation;
49
- const { step } = wheel;
50
+ const { step, smoothStep } = wheel;
50
51
 
51
52
  if (!contentComponent) {
52
53
  throw new Error("Component not mounted");
@@ -56,10 +57,11 @@ export const handleWheelZoom = (
56
57
  event.stopPropagation();
57
58
 
58
59
  const delta = getDelta(event, null);
60
+ const zoomStep = smooth ? smoothStep * Math.abs(event.deltaY) : step;
59
61
  const newScale = handleCalculateWheelZoom(
60
62
  contextInstance,
61
63
  delta,
62
- step,
64
+ zoomStep,
63
65
  !event.ctrlKey,
64
66
  );
65
67
 
@@ -66,8 +66,10 @@ export type ReactZoomPanPinchProps = {
66
66
  centerOnInit?: boolean;
67
67
  disablePadding?: boolean;
68
68
  customTransform?: (x: number, y: number, scale: number) => string;
69
+ smooth?: boolean;
69
70
  wheel?: {
70
71
  step?: number;
72
+ smoothStep?: number;
71
73
  disabled?: boolean;
72
74
  wheelDisabled?: boolean;
73
75
  touchPadDisabled?: boolean;
@@ -165,6 +165,12 @@ export const wrapperPropsTable: ComponentProps = {
165
165
  description:
166
166
  "We can provide custom transform function to provide different way of handling our transform logic. If we need performance we can import getMatrixTransformStyles functions and replace default one. WARNING: default transform prevents svg blur on the safari.",
167
167
  },
168
+ smooth: {
169
+ type: ["boolean"],
170
+ defaultValue: String(initialSetup.smooth),
171
+ description:
172
+ "Enable smooth scrolling by multiplying the scroll delta with the smooth step factor.",
173
+ },
168
174
  wheel: {
169
175
  wheel: {
170
176
  type: [""],
@@ -176,6 +182,12 @@ export const wrapperPropsTable: ComponentProps = {
176
182
  defaultValue: String(initialSetup.wheel.step),
177
183
  description: "The sensitivity of zooming with the wheel/touchpad.",
178
184
  },
185
+ smoothStep: {
186
+ type: ["number"],
187
+ defaultValue: String(initialSetup.wheel.smoothStep),
188
+ description:
189
+ "The sensitivity multiplier of zooming with the wheel/touchpad used, instead of the step value, when smooth scrolling is enabled.",
190
+ },
179
191
  disabled: {
180
192
  type: ["boolean"],
181
193
  defaultValue: String(initialSetup.wheel.disabled),
@@ -225,16 +237,16 @@ export const wrapperPropsTable: ComponentProps = {
225
237
  "Disable the panning velocity feature. It's triggered when you release the mouse button so the content is still moving after it and slowing down with calculated time.",
226
238
  },
227
239
  lockAxisX: {
228
- type: ["string[]"],
229
- defaultValue: String(initialSetup.panning.activationKeys),
240
+ type: ["boolean"],
241
+ defaultValue: String(initialSetup.panning.lockAxisX),
230
242
  description:
231
- "List of keys which, when held down, should activate this feature.",
243
+ "Disable the panning feature for the X axis (prevents horizontal panning).",
232
244
  },
233
245
  lockAxisY: {
234
- type: ["string[]"],
235
- defaultValue: String(initialSetup.panning.activationKeys),
246
+ type: ["boolean"],
247
+ defaultValue: String(initialSetup.panning.lockAxisY),
236
248
  description:
237
- "List of keys which, when held down, should activate this feature.",
249
+ "Disable the panning feature for the Y axis (prevents vertical panning).",
238
250
  },
239
251
  activationKeys: {
240
252
  type: ["string[]"],
@@ -326,7 +338,7 @@ export const wrapperPropsTable: ComponentProps = {
326
338
  },
327
339
  size: {
328
340
  type: ["number"],
329
- defaultValue: String(initialSetup.zoomAnimation.disabled),
341
+ defaultValue: String(initialSetup.zoomAnimation.size),
330
342
  description:
331
343
  "Thanks to size, we can control the zoom out values larger than that controlled by the value of another 'minScale' prop. This results in an animated return of the value to the minimum scale when the zooming has finished. This works for both touchpad zooming and pinching.",
332
344
  },
@@ -480,7 +492,7 @@ export const wrapperPropsTable: ComponentProps = {
480
492
  },
481
493
  onTransformed: {
482
494
  type: [
483
- "(ref: ReactZoomPanPinchRef, scale: number, positionX: number, positionY: number ) => void",
495
+ "(ref: ReactZoomPanPinchRef, state: { scale: number; positionX: number; positionY: number } ) => void",
484
496
  ],
485
497
  defaultValue: "undefined",
486
498
  description: "Callback fired when on each transform",
@@ -16,6 +16,16 @@ export const argsTypes = {
16
16
  defaultValue: { summary: "0" },
17
17
  },
18
18
  },
19
+ "wheel.smoothStep": {
20
+ defaultValue: initialSetup.wheel.smoothStep,
21
+ control: {
22
+ type: "number",
23
+ min: 0,
24
+ },
25
+ table: {
26
+ defaultValue: { summary: "0" },
27
+ },
28
+ },
19
29
  "wheel.disabled": {
20
30
  defaultValue: initialSetup.wheel.disabled,
21
31
  control: { type: "boolean" },