react-zoom-pan-pinch 4.0.3 → 4.0.5

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 CHANGED
@@ -10,11 +10,11 @@
10
10
  <a href="https://www.npmjs.com/package/react-zoom-pan-pinch">
11
11
  <img src="https://custom-icon-badges.demolab.com/npm/v/react-zoom-pan-pinch.svg?logo=npm&color=e22121"/>
12
12
  </a>
13
- <a href="https://github.com/prc5/react-zoom-pan-pinch">
14
- <img src="https://custom-icon-badges.demolab.com/github/stars/prc5/react-zoom-pan-pinch?logo=star" />
13
+ <a href="https://github.com/BetterTyped/react-zoom-pan-pinch">
14
+ <img src="https://custom-icon-badges.demolab.com/github/stars/BetterTyped/react-zoom-pan-pinch?logo=star&style=flat" />
15
15
  </a>
16
- <a href="https://github.com/prc5/react-zoom-pan-pinch/blob/main/License.md">
17
- <img src="https://custom-icon-badges.demolab.com/github/license/prc5/react-zoom-pan-pinch?logo=law&color=yellow" />
16
+ <a href="https://github.com/BetterTyped/react-zoom-pan-pinch/blob/main/License.md">
17
+ <img src="https://custom-icon-badges.demolab.com/github/license/BetterTyped/react-zoom-pan-pinch?logo=law&color=yellow" />
18
18
  </a>
19
19
  <a href="https://github.com/semantic-release/semantic-release">
20
20
  <img src="https://custom-icon-badges.demolab.com/badge/semver-commitzen-e10079?logo=semantic-release&color=e76f51" />
@@ -25,17 +25,28 @@
25
25
  <a href="https://www.npmjs.com/package/react-zoom-pan-pinch">
26
26
  <img src="https://custom-icon-badges.demolab.com/bundlephobia/minzip/react-zoom-pan-pinch?color=E10098&logo=package" />
27
27
  </a>
28
- <a href="https://github.com/prc5/react-zoom-pan-pinch">
28
+ <a href="https://github.com/BetterTyped/react-zoom-pan-pinch">
29
29
  <img src="https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
30
30
  </a>
31
- <a href="https://hits.sh/github.com/prc5/react-zoom-pan-pinch/">
32
- <img src="https://hits.sh/github.com/prc5/react-zoom-pan-pinch.svg?color=64BC4B&logo=bookmeter" />
31
+ <a href="https://hits.sh/github.com/BetterTyped/react-zoom-pan-pinch/">
32
+ <img src="https://hits.sh/github.com/BetterTyped/react-zoom-pan-pinch.svg?color=64BC4B&logo=bookmeter" />
33
33
  </a>
34
34
  <a href="https://twitter.com/maciej_pyrc">
35
- <img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/maciej_pyrc?label=Follow%20&style=social"/>
35
+ <img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/maciej_pyrc"/>
36
36
  </a>
37
37
  </p>
38
38
 
39
+ <p align="center">
40
+ <a href="https://www.hype-stack.dev/discord">
41
+ <img src="./.github/assets/discord.png" alt="Join our Discord community" />
42
+ </a>
43
+ </p>
44
+
45
+ ## 🏢 Using this library in production?
46
+
47
+ If your application depends on react-zoom-pan-pinch, I offer paid support to
48
+ help you resolve issues quickly and avoid blocking releases.
49
+
39
50
  #### Sources
40
51
 
41
52
  - [Demo](https://bettertyped.github.io/react-zoom-pan-pinch/?path=/story/basic-image--image)
@@ -69,14 +80,19 @@
69
80
 
70
81
  ## Try other BetterTyped projects
71
82
 
72
- Do you like this library? Try out other projects
83
+ Do you like this library? Here is what else I build and maintain.
73
84
 
74
- <a href="https://github.com/BetterTyped/hyper-fetch">
75
- <img width="200px" src="https://raw.githubusercontent.com/BetterTyped/hyper-fetch/main/.github/assets/readme.png" alt="Hyper Fetch" />
76
- </a>
85
+ <p align="center">
86
+ <a href="https://github.com/BetterTyped/hype-stack">
87
+ <img src="./.github/assets/banner-hype-stack.png" alt="Build your SaaS on Hype Stack" />
88
+ </a>
89
+ </p>
77
90
 
78
- **[⚡Hyper Fetch](https://github.com/BetterTyped/hyper-fetch)** - Fetching and
79
- realtime data exchange framework.
91
+ <p align="center">
92
+ <a href="https://github.com/BetterTyped/hyper-fetch">
93
+ <img src="./.github/assets/banner-hyper-fetch.png" alt="Connect any API with Hyper Fetch" />
94
+ </a>
95
+ </p>
80
96
 
81
97
  ---
82
98
 
@@ -125,8 +141,6 @@ const Example = () => {
125
141
  or
126
142
 
127
143
  ```jsx
128
- import React, { Component } from "react";
129
-
130
144
  import {
131
145
  TransformWrapper,
132
146
  TransformComponent,
@@ -138,9 +152,15 @@ const Controls = () => {
138
152
 
139
153
  return (
140
154
  <div className="tools">
141
- <button onClick={() => zoomIn()}>+</button>
142
- <button onClick={() => zoomOut()}>-</button>
143
- <button onClick={() => resetTransform()}>x</button>
155
+ <button type="button" onClick={() => zoomIn()}>
156
+ +
157
+ </button>
158
+ <button type="button" onClick={() => zoomOut()}>
159
+ -
160
+ </button>
161
+ <button type="button" onClick={() => resetTransform()}>
162
+ x
163
+ </button>
144
164
  </div>
145
165
  );
146
166
  };
@@ -152,15 +172,11 @@ const Example = () => {
152
172
  initialPositionX={200}
153
173
  initialPositionY={100}
154
174
  >
155
- {({ zoomIn, zoomOut, resetTransform, ...rest }) => (
156
- <>
157
- <Controls />
158
- <TransformComponent>
159
- <img src="image.jpg" alt="test" />
160
- <div>Example text</div>
161
- </TransformComponent>
162
- </>
163
- )}
175
+ <Controls />
176
+ <TransformComponent>
177
+ <img src="image.jpg" alt="test" />
178
+ <div>Example text</div>
179
+ </TransformComponent>
164
180
  </TransformWrapper>
165
181
  );
166
182
  };
@@ -182,10 +198,6 @@ const Example = () => {
182
198
  </a>
183
199
  </p>
184
200
 
185
- ## License
186
-
187
- MIT © [prc5](https://github.com/prc5)
188
-
189
201
  ## Help me keep working on this project ❤️
190
202
 
191
203
  - [Become a Sponsor on GitHub](https://github.com/sponsors/prc5)
@@ -197,3 +209,19 @@ MIT © [prc5](https://github.com/prc5)
197
209
  <img src="https://raw.githubusercontent.com/prc5/sponsors/main/packages/other/sponsorkit/sponsors.svg?raw=true" alt="My Sponsors" />
198
210
  </a>
199
211
  </p>
212
+
213
+ ## 🏢 Commercial Support
214
+
215
+ If you're using this library in production, I offer paid support:
216
+
217
+ - Priority issue resolution
218
+ - Help with debugging production issues
219
+ - Direct contact with the maintainer
220
+
221
+ Plans start at $400/month.
222
+
223
+ 📩 Contact: maciekpyrc@gmail.com
224
+
225
+ ## License
226
+
227
+ MIT © [prc5](https://github.com/prc5)
package/dist/index.cjs.js CHANGED
@@ -292,7 +292,7 @@ function getMouseBoundedPosition(positionX, positionY, bounds, limitToBounds, pa
292
292
  function handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale, bounds, limitToBounds) {
293
293
  var _a = contextInstance.state, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
294
294
  var scaleDifference = newScale - scale;
295
- if (typeof mouseX !== "number" || typeof mouseY !== "number") {
295
+ if (!Number.isFinite(mouseX) || !Number.isFinite(mouseY)) {
296
296
  console.error("Mouse X and Y position were not provided!");
297
297
  return { x: positionX, y: positionY };
298
298
  }
@@ -1249,8 +1249,10 @@ function getMousePosition(event, contentComponent, scale) {
1249
1249
  mouseX = (touch.clientX - contentRect.left) / scale;
1250
1250
  mouseY = (touch.clientY - contentRect.top) / scale;
1251
1251
  }
1252
- if (Number.isNaN(mouseX) || Number.isNaN(mouseY))
1252
+ if (Number.isNaN(mouseX) || Number.isNaN(mouseY)) {
1253
1253
  console.error("No mouse or touch offset found");
1254
+ return { x: 0, y: 0 };
1255
+ }
1254
1256
  return {
1255
1257
  x: mouseX,
1256
1258
  y: mouseY,
@@ -1366,7 +1368,9 @@ var handleWheelZoom = function (contextInstance, event) {
1366
1368
  if (!contentComponent) {
1367
1369
  throw new Error("Component not mounted");
1368
1370
  }
1369
- event.preventDefault();
1371
+ if (event.cancelable) {
1372
+ event.preventDefault();
1373
+ }
1370
1374
  event.stopPropagation();
1371
1375
  var delta = getDelta(event, null);
1372
1376
  var zoomStep = smooth ? step * Math.abs(event.deltaY) : step;
@@ -1736,7 +1740,9 @@ var ZoomPanPinch = /** @class */ (function () {
1736
1740
  var isAllowed = isWheelPanningAllowed(_this, event);
1737
1741
  if (!isAllowed)
1738
1742
  return;
1739
- event.preventDefault();
1743
+ if (event.cancelable) {
1744
+ event.preventDefault();
1745
+ }
1740
1746
  event.stopPropagation();
1741
1747
  var _a = _this.state, positionX = _a.positionX, positionY = _a.positionY;
1742
1748
  var mouseX = positionX - event.deltaX;
@@ -1774,7 +1780,9 @@ var ZoomPanPinch = /** @class */ (function () {
1774
1780
  return;
1775
1781
  if (event.button === 2 && !_this.setup.panning.allowRightClickPan)
1776
1782
  return;
1777
- event.preventDefault();
1783
+ if (event.cancelable) {
1784
+ event.preventDefault();
1785
+ }
1778
1786
  event.stopPropagation();
1779
1787
  handleCancelAnimation(_this);
1780
1788
  handlePanningStart(_this, event);
@@ -1798,7 +1806,9 @@ var ZoomPanPinch = /** @class */ (function () {
1798
1806
  var keysPressed = _this.isPressingKeys(_this.setup.panning.activationKeys);
1799
1807
  if (!keysPressed)
1800
1808
  return;
1801
- event.preventDefault();
1809
+ if (event.cancelable) {
1810
+ event.preventDefault();
1811
+ }
1802
1812
  event.stopPropagation();
1803
1813
  handlePanning(_this, event.clientX, event.clientY, exports.DeviceType.MOUSE);
1804
1814
  handleCallback(getContext(_this), event, onPanning);
@@ -1834,7 +1844,9 @@ var ZoomPanPinch = /** @class */ (function () {
1834
1844
  var isAllowed = isPinchAllowed(_this);
1835
1845
  if (!isAllowed)
1836
1846
  return;
1837
- event.preventDefault();
1847
+ if (event.cancelable) {
1848
+ event.preventDefault();
1849
+ }
1838
1850
  event.stopPropagation();
1839
1851
  handlePinchZoom(_this, event);
1840
1852
  handleCallback(getContext(_this), event, onPinch);