react-zoom-pan-pinch 4.0.3 → 4.0.4
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 +74 -34
- package/dist/index.cjs.js +19 -7
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +19 -7
- package/dist/index.esm.js.map +1 -1
- package/package.json +9 -9
- package/src/core/instance.core.ts +12 -4
- package/src/core/wheel/wheel.logic.ts +3 -1
- package/src/core/wheel/wheel.utils.ts +3 -1
- package/src/core/zoom/zoom.utils.ts +1 -1
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/
|
|
14
|
-
<img src="https://custom-icon-badges.demolab.com/github/stars/
|
|
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/
|
|
17
|
-
<img src="https://custom-icon-badges.demolab.com/github/license/
|
|
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/
|
|
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/
|
|
32
|
-
<img src="https://hits.sh/github.com/
|
|
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
|
|
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://discord.gg/DQXAJw36v">
|
|
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,31 @@
|
|
|
69
80
|
|
|
70
81
|
## Try other BetterTyped projects
|
|
71
82
|
|
|
72
|
-
Do you like this library?
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
Do you like this library? Here is another **BetterTyped** project — the whole
|
|
84
|
+
preview below is a single link to GitHub.
|
|
85
|
+
|
|
86
|
+
<div align="center">
|
|
87
|
+
<a href="https://github.com/BetterTyped/hyper-fetch">
|
|
88
|
+
<table>
|
|
89
|
+
<tr>
|
|
90
|
+
<td align="center" valign="middle" width="140">
|
|
91
|
+
<img
|
|
92
|
+
src="./.github/assets/hyper-fetch.svg"
|
|
93
|
+
width="112"
|
|
94
|
+
alt="Hyper Fetch logo"
|
|
95
|
+
/>
|
|
96
|
+
</td>
|
|
97
|
+
<td align="left" valign="middle">
|
|
98
|
+
<h3>⚡ Hyper Fetch</h3>
|
|
99
|
+
<p>
|
|
100
|
+
Fetching and realtime data exchange framework.
|
|
101
|
+
</p>
|
|
102
|
+
</br>
|
|
103
|
+
</td>
|
|
104
|
+
</tr>
|
|
105
|
+
</table>
|
|
106
|
+
</a>
|
|
107
|
+
</div>
|
|
80
108
|
|
|
81
109
|
---
|
|
82
110
|
|
|
@@ -125,8 +153,6 @@ const Example = () => {
|
|
|
125
153
|
or
|
|
126
154
|
|
|
127
155
|
```jsx
|
|
128
|
-
import React, { Component } from "react";
|
|
129
|
-
|
|
130
156
|
import {
|
|
131
157
|
TransformWrapper,
|
|
132
158
|
TransformComponent,
|
|
@@ -138,9 +164,15 @@ const Controls = () => {
|
|
|
138
164
|
|
|
139
165
|
return (
|
|
140
166
|
<div className="tools">
|
|
141
|
-
<button onClick={() => zoomIn()}
|
|
142
|
-
|
|
143
|
-
|
|
167
|
+
<button type="button" onClick={() => zoomIn()}>
|
|
168
|
+
+
|
|
169
|
+
</button>
|
|
170
|
+
<button type="button" onClick={() => zoomOut()}>
|
|
171
|
+
-
|
|
172
|
+
</button>
|
|
173
|
+
<button type="button" onClick={() => resetTransform()}>
|
|
174
|
+
x
|
|
175
|
+
</button>
|
|
144
176
|
</div>
|
|
145
177
|
);
|
|
146
178
|
};
|
|
@@ -152,15 +184,11 @@ const Example = () => {
|
|
|
152
184
|
initialPositionX={200}
|
|
153
185
|
initialPositionY={100}
|
|
154
186
|
>
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
<div>Example text</div>
|
|
161
|
-
</TransformComponent>
|
|
162
|
-
</>
|
|
163
|
-
)}
|
|
187
|
+
<Controls />
|
|
188
|
+
<TransformComponent>
|
|
189
|
+
<img src="image.jpg" alt="test" />
|
|
190
|
+
<div>Example text</div>
|
|
191
|
+
</TransformComponent>
|
|
164
192
|
</TransformWrapper>
|
|
165
193
|
);
|
|
166
194
|
};
|
|
@@ -182,10 +210,6 @@ const Example = () => {
|
|
|
182
210
|
</a>
|
|
183
211
|
</p>
|
|
184
212
|
|
|
185
|
-
## License
|
|
186
|
-
|
|
187
|
-
MIT © [prc5](https://github.com/prc5)
|
|
188
|
-
|
|
189
213
|
## Help me keep working on this project ❤️
|
|
190
214
|
|
|
191
215
|
- [Become a Sponsor on GitHub](https://github.com/sponsors/prc5)
|
|
@@ -197,3 +221,19 @@ MIT © [prc5](https://github.com/prc5)
|
|
|
197
221
|
<img src="https://raw.githubusercontent.com/prc5/sponsors/main/packages/other/sponsorkit/sponsors.svg?raw=true" alt="My Sponsors" />
|
|
198
222
|
</a>
|
|
199
223
|
</p>
|
|
224
|
+
|
|
225
|
+
## 🏢 Commercial Support
|
|
226
|
+
|
|
227
|
+
If you're using this library in production, I offer paid support:
|
|
228
|
+
|
|
229
|
+
- Priority issue resolution
|
|
230
|
+
- Help with debugging production issues
|
|
231
|
+
- Direct contact with the maintainer
|
|
232
|
+
|
|
233
|
+
Plans start at $400/month.
|
|
234
|
+
|
|
235
|
+
📩 Contact: maciekpyrc@gmail.com
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
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 (
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
1847
|
+
if (event.cancelable) {
|
|
1848
|
+
event.preventDefault();
|
|
1849
|
+
}
|
|
1838
1850
|
event.stopPropagation();
|
|
1839
1851
|
handlePinchZoom(_this, event);
|
|
1840
1852
|
handleCallback(getContext(_this), event, onPinch);
|