yet-another-react-lightbox 3.26.0 → 3.28.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/README.md +15 -0
- package/dist/plugins/zoom/index.d.ts +3 -1
- package/dist/plugins/zoom/index.js +21 -17
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -156,6 +156,21 @@ The following plugins are bundled in the package:
|
|
|
156
156
|
- [Zoom](https://yet-another-react-lightbox.com/plugins/zoom) - adds image zoom
|
|
157
157
|
feature
|
|
158
158
|
|
|
159
|
+
## Sponsors
|
|
160
|
+
|
|
161
|
+
This project is supported by the following companies, organizations and
|
|
162
|
+
individuals who help make its continued development and maintenance possible.
|
|
163
|
+
|
|
164
|
+
<p align="center">
|
|
165
|
+
<a target="_blank" rel="noreferrer noopener" href="https://cdn.jsdelivr.net/gh/igordanchenko/sponsors/sponsors.svg">
|
|
166
|
+
<img alt="Sponsors" src="https://cdn.jsdelivr.net/gh/igordanchenko/sponsors/sponsors.svg"/>
|
|
167
|
+
</a>
|
|
168
|
+
</p>
|
|
169
|
+
|
|
170
|
+
Support this project by becoming a
|
|
171
|
+
[sponsor](https://github.com/sponsors/igordanchenko). Both recurring and
|
|
172
|
+
one-time contributions are very much appreciated.
|
|
173
|
+
|
|
159
174
|
## License
|
|
160
175
|
|
|
161
176
|
MIT © 2022 [Igor Danchenko](https://github.com/igordanchenko)
|
|
@@ -26,8 +26,10 @@ declare module "yet-another-react-lightbox" {
|
|
|
26
26
|
keyboardMoveDistance?: number;
|
|
27
27
|
/** wheel zoom distance factor */
|
|
28
28
|
wheelZoomDistanceFactor?: number;
|
|
29
|
-
/** pinch zoom distance factor */
|
|
29
|
+
/** @deprecated - pinch zoom distance factor */
|
|
30
30
|
pinchZoomDistanceFactor?: number;
|
|
31
|
+
/** if `true`, enables the experimental pinch zoom implementation slated for v4 */
|
|
32
|
+
pinchZoomV4?: boolean;
|
|
31
33
|
/** if `true`, enables image zoom via scroll gestures for mouse and trackpad users */
|
|
32
34
|
scrollToZoom?: boolean;
|
|
33
35
|
};
|
|
@@ -12,6 +12,7 @@ const defaultZoomProps = {
|
|
|
12
12
|
keyboardMoveDistance: 50,
|
|
13
13
|
wheelZoomDistanceFactor: 100,
|
|
14
14
|
pinchZoomDistanceFactor: 100,
|
|
15
|
+
pinchZoomV4: false,
|
|
15
16
|
scrollToZoom: false,
|
|
16
17
|
};
|
|
17
18
|
function validateMinZoom(minZoom) {
|
|
@@ -117,7 +118,7 @@ function useZoomImageRect(slideRect, imageDimensions) {
|
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
function distance(pointerA, pointerB) {
|
|
120
|
-
return (
|
|
121
|
+
return Math.hypot(pointerA.clientX - pointerB.clientX, pointerA.clientY - pointerB.clientY);
|
|
121
122
|
}
|
|
122
123
|
function scaleZoom(value, delta, factor = 100, clamp = 2) {
|
|
123
124
|
return value * Math.min(1 + Math.abs(delta / factor), clamp) ** Math.sign(delta);
|
|
@@ -125,11 +126,11 @@ function scaleZoom(value, delta, factor = 100, clamp = 2) {
|
|
|
125
126
|
function useZoomSensors(zoom, minZoom, maxZoom, disabled, zoomIn, zoomOut, changeZoom, changeOffsets, zoomWrapperRef) {
|
|
126
127
|
const activePointers = React.useRef([]);
|
|
127
128
|
const lastPointerDown = React.useRef(0);
|
|
128
|
-
const
|
|
129
|
+
const pinchZoom = React.useRef(undefined);
|
|
129
130
|
const { globalIndex } = useLightboxState();
|
|
130
131
|
const { getOwnerWindow } = useDocumentContext();
|
|
131
132
|
const { containerRef, subscribeSensors } = useController();
|
|
132
|
-
const { keyboardMoveDistance, zoomInMultiplier, wheelZoomDistanceFactor, scrollToZoom, doubleTapDelay, doubleClickDelay, doubleClickMaxStops, pinchZoomDistanceFactor, } = useZoomProps();
|
|
133
|
+
const { keyboardMoveDistance, zoomInMultiplier, wheelZoomDistanceFactor, scrollToZoom, doubleTapDelay, doubleClickDelay, doubleClickMaxStops, pinchZoomDistanceFactor, pinchZoomV4, } = useZoomProps();
|
|
133
134
|
const translateCoordinates = React.useCallback((event) => {
|
|
134
135
|
if (containerRef.current) {
|
|
135
136
|
const { pageX, pageY } = event;
|
|
@@ -229,23 +230,28 @@ function useZoomSensors(zoom, minZoom, maxZoom, disabled, zoomIn, zoomOut, chang
|
|
|
229
230
|
}
|
|
230
231
|
replacePointer(event);
|
|
231
232
|
if (pointers.length === 2) {
|
|
232
|
-
|
|
233
|
+
const initialDistance = distance(pointers[0], pointers[1]);
|
|
234
|
+
pinchZoom.current = {
|
|
235
|
+
previousDistance: initialDistance,
|
|
236
|
+
initialDistance: Math.max(initialDistance, 1),
|
|
237
|
+
initialZoom: zoom,
|
|
238
|
+
};
|
|
233
239
|
}
|
|
234
240
|
});
|
|
235
241
|
const onPointerMove = useEventCallback((event) => {
|
|
236
242
|
const pointers = activePointers.current;
|
|
237
243
|
const activePointer = pointers.find((p) => p.pointerId === event.pointerId);
|
|
238
|
-
if (pointers.length === 2 &&
|
|
244
|
+
if (pointers.length === 2 && pinchZoom.current) {
|
|
239
245
|
event.stopPropagation();
|
|
240
246
|
replacePointer(event);
|
|
241
247
|
const currentDistance = distance(pointers[0], pointers[1]);
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
248
|
+
const targetZoom = pinchZoomV4
|
|
249
|
+
? (pinchZoom.current.initialZoom / pinchZoom.current.initialDistance) * currentDistance
|
|
250
|
+
: scaleZoom(zoom, currentDistance - pinchZoom.current.previousDistance, pinchZoomDistanceFactor);
|
|
251
|
+
changeZoom(targetZoom, true, ...pointers
|
|
252
|
+
.map((x) => translateCoordinates(x))
|
|
253
|
+
.reduce((acc, coordinate) => coordinate.map((x, i) => acc[i] + x / 2)));
|
|
254
|
+
pinchZoom.current.previousDistance = currentDistance;
|
|
249
255
|
return;
|
|
250
256
|
}
|
|
251
257
|
if (zoom > 1) {
|
|
@@ -261,7 +267,7 @@ function useZoomSensors(zoom, minZoom, maxZoom, disabled, zoomIn, zoomOut, chang
|
|
|
261
267
|
const onPointerUp = React.useCallback((event) => {
|
|
262
268
|
const pointers = activePointers.current;
|
|
263
269
|
if (pointers.length === 2 && pointers.find((p) => p.pointerId === event.pointerId)) {
|
|
264
|
-
|
|
270
|
+
pinchZoom.current = undefined;
|
|
265
271
|
}
|
|
266
272
|
clearPointer(event);
|
|
267
273
|
}, [clearPointer]);
|
|
@@ -269,7 +275,7 @@ function useZoomSensors(zoom, minZoom, maxZoom, disabled, zoomIn, zoomOut, chang
|
|
|
269
275
|
const pointers = activePointers.current;
|
|
270
276
|
pointers.splice(0, pointers.length);
|
|
271
277
|
lastPointerDown.current = 0;
|
|
272
|
-
|
|
278
|
+
pinchZoom.current = undefined;
|
|
273
279
|
}, []);
|
|
274
280
|
usePointerEvents(subscribeSensors, onPointerDown, onPointerMove, onPointerUp, disabled);
|
|
275
281
|
React.useEffect(cleanupSensors, [globalIndex, cleanupSensors]);
|
|
@@ -306,9 +312,7 @@ function useZoomState(imageRect, maxZoom, zoomWrapperRef) {
|
|
|
306
312
|
setOffsetY(Math.min(Math.abs(newOffsetY), Math.max(maxOffsetY, 0)) * Math.sign(newOffsetY));
|
|
307
313
|
}, [zoom, offsetX, offsetY, slideRect, imageRect.width, imageRect.height]);
|
|
308
314
|
const changeZoom = React.useCallback((targetZoom, rapid, dx, dy) => {
|
|
309
|
-
const newZoom = round(
|
|
310
|
-
if (newZoom === zoom)
|
|
311
|
-
return;
|
|
315
|
+
const newZoom = round(targetZoom + 0.01 < maxZoom ? (targetZoom - 0.01 > minZoom ? targetZoom : minZoom) : maxZoom, 5);
|
|
312
316
|
if (!rapid) {
|
|
313
317
|
animate();
|
|
314
318
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yet-another-react-lightbox",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.28.0",
|
|
4
4
|
"description": "Modern React lightbox component",
|
|
5
5
|
"author": "Igor Danchenko",
|
|
6
6
|
"license": "MIT",
|
|
@@ -139,13 +139,12 @@
|
|
|
139
139
|
"*.css"
|
|
140
140
|
],
|
|
141
141
|
"homepage": "https://yet-another-react-lightbox.com",
|
|
142
|
+
"funding": "https://github.com/sponsors/igordanchenko",
|
|
143
|
+
"bugs": "https://github.com/igordanchenko/yet-another-react-lightbox/issues",
|
|
142
144
|
"repository": {
|
|
143
145
|
"type": "git",
|
|
144
146
|
"url": "git+https://github.com/igordanchenko/yet-another-react-lightbox.git"
|
|
145
147
|
},
|
|
146
|
-
"bugs": {
|
|
147
|
-
"url": "https://github.com/igordanchenko/yet-another-react-lightbox/issues"
|
|
148
|
-
},
|
|
149
148
|
"engines": {
|
|
150
149
|
"node": ">=14"
|
|
151
150
|
},
|