yet-another-react-lightbox 1.9.0 → 1.9.3
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 +1 -1
- package/dist/plugins/Zoom.js +17 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -136,7 +136,7 @@ The following plugins come bundled in the package:
|
|
|
136
136
|
- [Slideshow](https://yet-another-react-lightbox.vercel.app/plugins/slideshow) - adds slideshow autoplay feature
|
|
137
137
|
- [Thumbnails](https://yet-another-react-lightbox.vercel.app/plugins/thumbnails) - adds thumbnails track
|
|
138
138
|
- [Video](https://yet-another-react-lightbox.vercel.app/plugins/video) - adds support for video slides
|
|
139
|
-
- [Zoom](https://yet-another-react-lightbox.vercel.app/plugins/zoom) - adds zoom feature
|
|
139
|
+
- [Zoom](https://yet-another-react-lightbox.vercel.app/plugins/zoom) - adds image zoom feature
|
|
140
140
|
|
|
141
141
|
## License
|
|
142
142
|
|
package/dist/plugins/Zoom.js
CHANGED
|
@@ -92,12 +92,12 @@ const ZoomButtonsGroup = ({ labels, render }) => {
|
|
|
92
92
|
React.createElement(ZoomButton, { ref: zoomOutRef, key: "zoomOut", labels: labels, render: render, onLoseFocus: focusZoomIn })));
|
|
93
93
|
};
|
|
94
94
|
const getSlideRects = (slide, cover, maxZoomPixelRatio, rect) => {
|
|
95
|
-
var _a, _b;
|
|
95
|
+
var _a, _b, _c;
|
|
96
96
|
let slideRect = { width: 0, height: 0 };
|
|
97
97
|
let maxSlideRect = { width: 0, height: 0 };
|
|
98
98
|
if (rect && !("type" in slide) && "src" in slide) {
|
|
99
|
-
const width = Math.max(...(((_a = slide.srcSet) === null || _a === void 0 ? void 0 : _a.map((x) => x.width)) || [])
|
|
100
|
-
const height = Math.max(...(((_b = slide.srcSet) === null || _b === void 0 ? void 0 : _b.map((x) => x.
|
|
99
|
+
const width = Math.max(...(((_a = slide.srcSet) === null || _a === void 0 ? void 0 : _a.map((x) => x.width)) || []).concat(slide.width ? [slide.width] : []));
|
|
100
|
+
const height = Math.max(...((_c = (_b = slide.srcSet) === null || _b === void 0 ? void 0 : _b.map((x) => x.height).filter((x) => Boolean(x))) !== null && _c !== void 0 ? _c : (slide.aspectRatio ? [width / slide.aspectRatio] : [])).concat(slide.height ? [slide.height] : []));
|
|
101
101
|
if (width > 0 && height > 0 && rect.width > 0 && rect.height > 0) {
|
|
102
102
|
maxSlideRect = cover
|
|
103
103
|
? {
|
|
@@ -132,7 +132,9 @@ const ZoomContainer = ({ slide, offset, rect, render, carousel, animation, zoom:
|
|
|
132
132
|
const { subscribe } = useEvents();
|
|
133
133
|
const currentReduceMotion = useMotionPreference();
|
|
134
134
|
const { slideRect: currentSlideRect, maxSlideRect: currentMaxSlideRect } = getSlideRects(slide, carousel.imageFit === "cover" || ("imageFit" in slide && slide.imageFit === "cover"), zoomProps.maxZoomPixelRatio, currentContainerRect);
|
|
135
|
-
const currentMaxZoom = currentSlideRect.width
|
|
135
|
+
const currentMaxZoom = currentSlideRect.width
|
|
136
|
+
? Math.max(round(currentMaxSlideRect.width / currentSlideRect.width, 5), 1)
|
|
137
|
+
: 1;
|
|
136
138
|
const [state, setState] = React.useState({ zoom: 1, offsetX: 0, offsetY: 0 });
|
|
137
139
|
const refs = React.useRef({
|
|
138
140
|
state,
|
|
@@ -202,13 +204,6 @@ const ZoomContainer = ({ slide, offset, rect, render, carousel, animation, zoom:
|
|
|
202
204
|
}
|
|
203
205
|
}
|
|
204
206
|
}, [state.zoom, state.offsetX, state.offsetY]);
|
|
205
|
-
useEnhancedEffect(() => {
|
|
206
|
-
if (offset === 0) {
|
|
207
|
-
const { setMinZoom, setMaxZoom, maxZoom } = refs.current;
|
|
208
|
-
setMinZoom(state.zoom <= 1);
|
|
209
|
-
setMaxZoom(state.zoom >= maxZoom);
|
|
210
|
-
}
|
|
211
|
-
}, [offset, state.zoom]);
|
|
212
207
|
useEnhancedEffect(() => {
|
|
213
208
|
if (offset === 0) {
|
|
214
209
|
const { setMinZoom, setMaxZoom } = refs.current;
|
|
@@ -224,12 +219,19 @@ const ZoomContainer = ({ slide, offset, rect, render, carousel, animation, zoom:
|
|
|
224
219
|
}
|
|
225
220
|
return () => { };
|
|
226
221
|
}, [offset]);
|
|
222
|
+
useEnhancedEffect(() => {
|
|
223
|
+
if (offset === 0) {
|
|
224
|
+
const { setMinZoom, setMaxZoom } = refs.current;
|
|
225
|
+
setMinZoom(state.zoom <= 1);
|
|
226
|
+
setMaxZoom(state.zoom >= currentMaxZoom);
|
|
227
|
+
}
|
|
228
|
+
}, [offset, state.zoom, currentMaxZoom]);
|
|
227
229
|
const changeZoom = React.useCallback((value, rapid, dx, dy) => {
|
|
228
230
|
const { current } = refs;
|
|
229
231
|
const { state: { zoom }, containerRef, containerRect, maxZoom, } = current;
|
|
230
232
|
if (!containerRef.current || !containerRect)
|
|
231
233
|
return;
|
|
232
|
-
const newZoom = round(Math.min(Math.max(value, 1), maxZoom), 5);
|
|
234
|
+
const newZoom = round(Math.min(Math.max(value + 0.001 < maxZoom ? value : maxZoom, 1), maxZoom), 5);
|
|
233
235
|
if (newZoom === zoom)
|
|
234
236
|
return;
|
|
235
237
|
if (!rapid) {
|
|
@@ -377,7 +379,7 @@ const ZoomContainer = ({ slide, offset, rect, render, carousel, animation, zoom:
|
|
|
377
379
|
? { style: { transform: `scale(${zoom}) translate3d(${offsetX}px, ${offsetY}px, 0)` } }
|
|
378
380
|
: null) }, rendered)) : null;
|
|
379
381
|
};
|
|
380
|
-
const ZoomWrapper = ({ slide, offset, rect, render, carousel, animation }) => {
|
|
382
|
+
const ZoomWrapper = ({ slide, offset, rect, render, carousel, animation, zoom }) => {
|
|
381
383
|
var _a;
|
|
382
384
|
const { setZoomSupported } = useZoom();
|
|
383
385
|
const imageSlide = !("type" in slide);
|
|
@@ -388,7 +390,7 @@ const ZoomWrapper = ({ slide, offset, rect, render, carousel, animation }) => {
|
|
|
388
390
|
}
|
|
389
391
|
}, [offset, zoomSupported, setZoomSupported]);
|
|
390
392
|
if (zoomSupported) {
|
|
391
|
-
return (React.createElement(ZoomContainer, { slide: slide, offset: offset, rect: rect, render: render, carousel: carousel, animation: animation }));
|
|
393
|
+
return (React.createElement(ZoomContainer, { slide: slide, offset: offset, rect: rect, render: render, carousel: carousel, animation: animation, zoom: zoom }));
|
|
392
394
|
}
|
|
393
395
|
const rendered = (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, slide, offset, rect);
|
|
394
396
|
if (rendered) {
|
|
@@ -408,7 +410,7 @@ export const Zoom = ({ augment, append }) => {
|
|
|
408
410
|
},
|
|
409
411
|
render: {
|
|
410
412
|
...render,
|
|
411
|
-
slide: (slide, offset, rect) => (React.createElement(ZoomWrapper, { slide: slide, offset: offset, rect: rect, render: render, carousel: carousel, animation: animation })),
|
|
413
|
+
slide: (slide, offset, rect) => (React.createElement(ZoomWrapper, { slide: slide, offset: offset, rect: rect, render: render, carousel: carousel, animation: animation, zoom: zoom })),
|
|
412
414
|
},
|
|
413
415
|
zoom: {
|
|
414
416
|
...defaultZoomProps,
|