react-zoom-pan-pinch 3.4.2 → 3.4.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 CHANGED
@@ -36,14 +36,27 @@
36
36
  </a>
37
37
  </p>
38
38
 
39
- Do you like this library? Try out other projects
40
- **[⚡Hyper Fetch](https://github.com/BetterTyped/hyper-fetch)**
41
-
42
39
  #### Sources
43
40
 
44
41
  - [Demo](https://BetterTyped.github.io/react-zoom-pan-pinch/?path=/story/examples-big-image--big-image)
45
42
  - [Docs](https://BetterTyped.github.io/react-zoom-pan-pinch/?path=/story/docs-props--page)
46
43
 
44
+ <p align="center">
45
+ <a href="https://github.com/sponsors/prc5?tier=platinum">
46
+ <picture>
47
+ <img width="830" src="https://raw.githubusercontent.com/prc5/sponsors/main/assets/Platinum.png" alt="Premium sponsor banner"/>
48
+ </picture>
49
+ </a>
50
+ </p>
51
+
52
+ <p align="center">
53
+ <a href="https://github.com/sponsors/prc5?tier=Platinum">
54
+ <picture>
55
+ <img width="830" src="https://raw.githubusercontent.com/prc5/sponsors/main/packages/platinum/sponsorkit/sponsors.svg" alt="Premium sponsor banner"/>
56
+ </picture>
57
+ </a>
58
+ </p>
59
+
47
60
  ## Key Features
48
61
 
49
62
  - 🚀 Fast and easy to use
@@ -54,9 +67,16 @@ Do you like this library? Try out other projects
54
67
  - 👑 Animations and Utils to create own tools
55
68
  - 🔮 Advanced hooks and components
56
69
 
57
- ## Help me keep working on this project ❤️
70
+ ## Try other BetterTyped projects
58
71
 
59
- - [Become a Sponsor on GitHub](https://github.com/sponsors/prc5)
72
+ Do you like this library? Try out other projects
73
+
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>
77
+
78
+ **[⚡Hyper Fetch](https://github.com/BetterTyped/hyper-fetch)** - Fetching and
79
+ realtime data exchange framework.
60
80
 
61
81
  ---
62
82
 
@@ -68,6 +88,22 @@ or
68
88
  yarn add react-zoom-pan-pinch
69
89
  ```
70
90
 
91
+ <p align="center">
92
+ <a href="https://github.com/sponsors/prc5?tier=Gold">
93
+ <picture>
94
+ <img width="830" src="https://raw.githubusercontent.com/prc5/sponsors/main/assets/Gold.png" alt="Premium sponsor banner"/>
95
+ </picture>
96
+ </a>
97
+ </p>
98
+
99
+ <p align="center">
100
+ <a href="https://github.com/sponsors/prc5?tier=gold">
101
+ <picture>
102
+ <img width="830" src="https://raw.githubusercontent.com/prc5/sponsors/main/packages/gold/sponsorkit/sponsors.svg" alt="Premium sponsor banner"/>
103
+ </picture>
104
+ </a>
105
+ </p>
106
+
71
107
  ## Examples
72
108
 
73
109
  ```jsx
@@ -91,7 +127,23 @@ or
91
127
  ```jsx
92
128
  import React, { Component } from "react";
93
129
 
94
- import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
130
+ import {
131
+ TransformWrapper,
132
+ TransformComponent,
133
+ useControls,
134
+ } from "react-zoom-pan-pinch";
135
+
136
+ const Controls = () => {
137
+ const { zoomIn, zoomOut, resetTransform } = useControls();
138
+
139
+ return (
140
+ <div className="tools">
141
+ <button onClick={() => zoomIn()}>+</button>
142
+ <button onClick={() => zoomOut()}>-</button>
143
+ <button onClick={() => resetTransform()}>x</button>
144
+ </div>
145
+ );
146
+ };
95
147
 
96
148
  const Example = () => {
97
149
  return (
@@ -101,72 +153,47 @@ const Example = () => {
101
153
  initialPositionY={100}
102
154
  >
103
155
  {({ zoomIn, zoomOut, resetTransform, ...rest }) => (
104
- <React.Fragment>
105
- <div className="tools">
106
- <button onClick={() => zoomIn()}>+</button>
107
- <button onClick={() => zoomOut()}>-</button>
108
- <button onClick={() => resetTransform()}>x</button>
109
- </div>
156
+ <>
157
+ <Controls />
110
158
  <TransformComponent>
111
159
  <img src="image.jpg" alt="test" />
112
160
  <div>Example text</div>
113
161
  </TransformComponent>
114
- </React.Fragment>
162
+ </>
115
163
  )}
116
164
  </TransformWrapper>
117
165
  );
118
166
  };
119
167
  ```
120
168
 
121
- or
169
+ <p align="center">
170
+ <a href="https://github.com/sponsors/prc5?tier=Silver">
171
+ <picture>
172
+ <img width="830" src="https://raw.githubusercontent.com/prc5/sponsors/main/assets/Silver.png" alt="Premium sponsor banner" />
173
+ </picture>
174
+ </a>
175
+ </p>
122
176
 
123
- ```tsx
124
- import React, { useRef } from "react";
125
- import {
126
- TransformWrapper,
127
- TransformComponent,
128
- ReactZoomPanPinchRef,
129
- } from "react-zoom-pan-pinch";
177
+ <p align="center">
178
+ <a href="https://github.com/sponsors/prc5?tier=Silver">
179
+ <picture>
180
+ <img width="830" src="https://raw.githubusercontent.com/prc5/sponsors/main/packages/silver/sponsorkit/sponsors.svg" alt="Premium sponsor banner" />
181
+ </picture>
182
+ </a>
183
+ </p>
130
184
 
131
- const Controls = ({ zoomIn, zoomOut, resetTransform }) => (
132
- <>
133
- <button onClick={() => zoomIn()}>+</button>
134
- <button onClick={() => zoomOut()}>-</button>
135
- <button onClick={() => resetTransform()}>x</button>
136
- </>
137
- );
185
+ ## License
138
186
 
139
- const Component = () => {
140
- const transformComponentRef = useRef<ReactZoomPanPinchRef | null>(null);
187
+ MIT © [prc5](https://github.com/prc5)
141
188
 
142
- const zoomToImage = () => {
143
- if (transformComponentRef.current) {
144
- const { zoomToElement } = transformComponentRef.current;
145
- zoomToElement("imgExample");
146
- }
147
- };
189
+ ## Help me keep working on this project ❤️
148
190
 
149
- return (
150
- <TransformWrapper
151
- initialScale={1}
152
- initialPositionX={200}
153
- initialPositionY={100}
154
- ref={transformComponentRef}
155
- >
156
- {(utils) => (
157
- <React.Fragment>
158
- <Controls {...utils} />
159
- <TransformComponent>
160
- <img src="image.jpg" alt="test" id="imgExample" />
161
- <div onClick={zoomToImage}>Example text</div>
162
- </TransformComponent>
163
- </React.Fragment>
164
- )}
165
- </TransformWrapper>
166
- );
167
- };
168
- ```
191
+ - [Become a Sponsor on GitHub](https://github.com/sponsors/prc5)
169
192
 
170
- ## License
193
+ ## 💖 Our sponsors
171
194
 
172
- MIT © [prc5](https://github.com/prc5)
195
+ <p align="center">
196
+ <a href="https://github.com/sponsors/prc5">
197
+ <img src="https://raw.githubusercontent.com/prc5/sponsors/main/packages/other/sponsorkit/sponsors.svg?raw=true" alt="My Sponsors" />
198
+ </a>
199
+ </p>
package/dist/index.cjs.js CHANGED
@@ -1408,10 +1408,19 @@ var ZoomPanPinch = /** @class */ (function () {
1408
1408
  _this.setCenter();
1409
1409
  _this.observer = new ResizeObserver(function () {
1410
1410
  var _a;
1411
- _this.onInitCallbacks.forEach(function (callback) { return callback(getContext(_this)); });
1412
- _this.setCenter();
1413
- (_a = _this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
1411
+ var currentWidth = contentComponent.offsetWidth;
1412
+ var currentHeight = contentComponent.offsetHeight;
1413
+ if (currentWidth > 0 || currentHeight > 0) {
1414
+ _this.onInitCallbacks.forEach(function (callback) { return callback(getContext(_this)); });
1415
+ _this.setCenter();
1416
+ (_a = _this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
1417
+ }
1414
1418
  });
1419
+ // if nothing about the contentComponent has changed after 5 seconds, disconnect the observer
1420
+ setTimeout(function () {
1421
+ var _a;
1422
+ (_a = _this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
1423
+ }, 5000);
1415
1424
  // Start observing the target node for configured mutations
1416
1425
  _this.observer.observe(contentComponent);
1417
1426
  }
@@ -1763,6 +1772,9 @@ var useResize = function (ref, onResize, dependencies) {
1763
1772
  React.useLayoutEffect(function () {
1764
1773
  var _a;
1765
1774
  didUnmount.current = false;
1775
+ if (!("ResizeObserver" in window)) {
1776
+ return;
1777
+ }
1766
1778
  if (ref) {
1767
1779
  resizeObserverRef.current = new ResizeObserver(function (entries) {
1768
1780
  var newSize = ref.getBoundingClientRect();