yet-another-react-lightbox 1.10.0 → 1.11.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/dist/core/components/ImageSlide.d.ts +2 -1
- package/dist/core/components/ImageSlide.js +2 -2
- package/dist/core/hooks/useLatest.d.ts +1 -0
- package/dist/core/modules/Carousel.js +7 -2
- package/dist/plugins/Video.js +5 -2
- package/dist/plugins/Zoom.d.ts +2 -0
- package/dist/plugins/Zoom.js +9 -6
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
|
@@ -7,5 +7,6 @@ export declare type ImageSlideProps = {
|
|
|
7
7
|
render?: Render;
|
|
8
8
|
rect?: ContainerRect;
|
|
9
9
|
imageFit?: ImageFit;
|
|
10
|
+
onClick?: () => void;
|
|
10
11
|
};
|
|
11
|
-
export declare const ImageSlide: ({ slide: image, offset, render, rect, imageFit }: ImageSlideProps) => JSX.Element;
|
|
12
|
+
export declare const ImageSlide: ({ slide: image, offset, render, rect, imageFit, onClick }: ImageSlideProps) => JSX.Element;
|
|
@@ -4,7 +4,7 @@ import { useLatest } from "../hooks/index.js";
|
|
|
4
4
|
import { useEvents } from "../contexts/index.js";
|
|
5
5
|
import { ErrorIcon, LoadingIcon } from "./Icons.js";
|
|
6
6
|
import { activeSlideStatus, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, } from "../consts.js";
|
|
7
|
-
export const ImageSlide = ({ slide: image, offset, render, rect, imageFit }) => {
|
|
7
|
+
export const ImageSlide = ({ slide: image, offset, render, rect, imageFit, onClick }) => {
|
|
8
8
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
9
9
|
const [status, setStatus] = React.useState(SLIDE_STATUS_LOADING);
|
|
10
10
|
const latestStatus = useLatest(status);
|
|
@@ -61,7 +61,7 @@ export const ImageSlide = ({ slide: image, offset, render, rect, imageFit }) =>
|
|
|
61
61
|
? `${Math.ceil((Math.min(estimateActualWidth(), rect.width) / window.innerWidth) * 100)}vw`
|
|
62
62
|
: undefined;
|
|
63
63
|
return (React.createElement(React.Fragment, null,
|
|
64
|
-
React.createElement("img", { ref: setImageRef, onLoad: onLoad, onError: onError, className: clsx(cssClass("slide_image"), cssClass("fullsize"), cover && cssClass("slide_image_cover"), status !== SLIDE_STATUS_COMPLETE && cssClass("slide_image_loading")), draggable: false, alt: image.alt, style: style, sizes: sizes, srcSet: srcSet, src: image.src }),
|
|
64
|
+
React.createElement("img", { ref: setImageRef, onLoad: onLoad, onError: onError, onClick: onClick, className: clsx(cssClass("slide_image"), cssClass("fullsize"), cover && cssClass("slide_image_cover"), status !== SLIDE_STATUS_COMPLETE && cssClass("slide_image_loading")), draggable: false, alt: image.alt, style: style, sizes: sizes, srcSet: srcSet, src: image.src }),
|
|
65
65
|
status !== SLIDE_STATUS_COMPLETE && (React.createElement("div", { className: cssClass("slide_placeholder") },
|
|
66
66
|
status === SLIDE_STATUS_LOADING &&
|
|
67
67
|
((render === null || render === void 0 ? void 0 : render.iconLoading) ? (render.iconLoading()) : (React.createElement(LoadingIcon, { className: clsx(cssClass("icon"), cssClass("slide_loading")) }))),
|
|
@@ -7,13 +7,18 @@ import { ImageSlide } from "../components/index.js";
|
|
|
7
7
|
import { useController } from "./Controller.js";
|
|
8
8
|
const CarouselSlide = ({ slide, offset }) => {
|
|
9
9
|
const { setContainerRef, containerRect } = useContainerRect();
|
|
10
|
-
const { latestProps } = useController();
|
|
10
|
+
const { latestProps, currentIndex } = useController();
|
|
11
11
|
const { render } = latestProps.current;
|
|
12
12
|
const renderSlide = (rect) => {
|
|
13
13
|
var _a, _b, _c, _d;
|
|
14
14
|
let rendered = (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, slide, offset, rect);
|
|
15
15
|
if (!rendered && "src" in slide) {
|
|
16
|
-
rendered = (React.createElement(ImageSlide, { slide: slide, offset: offset, render: render, rect: rect, imageFit: latestProps.current.carousel.imageFit
|
|
16
|
+
rendered = (React.createElement(ImageSlide, { slide: slide, offset: offset, render: render, rect: rect, imageFit: latestProps.current.carousel.imageFit, onClick: latestProps.current.on.click && offset === 0
|
|
17
|
+
? () => {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
(_b = (_a = latestProps.current.on).click) === null || _b === void 0 ? void 0 : _b.call(_a, currentIndex);
|
|
20
|
+
}
|
|
21
|
+
: undefined }));
|
|
17
22
|
}
|
|
18
23
|
return rendered ? (React.createElement(React.Fragment, null, (_b = render.slideHeader) === null || _b === void 0 ? void 0 :
|
|
19
24
|
_b.call(render, slide),
|
package/dist/plugins/Video.js
CHANGED
|
@@ -39,9 +39,12 @@ export const VideoSlide = ({ slide, offset }) => {
|
|
|
39
39
|
if (!width || !height || !containerRect)
|
|
40
40
|
return null;
|
|
41
41
|
const widthBound = width / height > containerRect.width / containerRect.height;
|
|
42
|
+
const elementWidth = widthBound ? containerRect.width : Math.round((containerRect.height / height) * width);
|
|
43
|
+
const elementHeight = !widthBound ? containerRect.height : Math.round((containerRect.width / width) * height);
|
|
42
44
|
return {
|
|
43
|
-
width:
|
|
44
|
-
height:
|
|
45
|
+
width: elementWidth,
|
|
46
|
+
height: elementHeight,
|
|
47
|
+
style: { width: elementWidth, height: elementHeight, maxWidth: "100%", maxHeight: "100%" },
|
|
45
48
|
};
|
|
46
49
|
};
|
|
47
50
|
const resolveBoolean = (attr) => {
|
package/dist/plugins/Zoom.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ declare module "../types.js" {
|
|
|
28
28
|
wheelZoomDistanceFactor?: number;
|
|
29
29
|
/** pinch zoom distance factor */
|
|
30
30
|
pinchZoomDistanceFactor?: number;
|
|
31
|
+
/** if `true`, enables image zoom via scroll gestures for mouse and trackpad users */
|
|
32
|
+
scrollToZoom?: boolean;
|
|
31
33
|
};
|
|
32
34
|
}
|
|
33
35
|
interface AnimationSettings {
|
package/dist/plugins/Zoom.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { cleanup, clsx, createIcon, createModule, cssClass, IconButton, ImageSlide, label, makeUseContext, round, useContainerRect, useController,
|
|
2
|
+
import { cleanup, clsx, createIcon, createModule, cssClass, IconButton, ImageSlide, label, makeUseContext, round, useContainerRect, useController, useEvents, useLayoutEffect, useMotionPreference, } from "../core/index.js";
|
|
3
3
|
const defaultZoomProps = {
|
|
4
4
|
maxZoomPixelRatio: 1,
|
|
5
5
|
zoomInMultiplier: 2,
|
|
@@ -9,6 +9,7 @@ const defaultZoomProps = {
|
|
|
9
9
|
keyboardMoveDistance: 50,
|
|
10
10
|
wheelZoomDistanceFactor: 100,
|
|
11
11
|
pinchZoomDistanceFactor: 100,
|
|
12
|
+
scrollToZoom: false,
|
|
12
13
|
};
|
|
13
14
|
const ZoomInIcon = createIcon("ZoomIn", React.createElement(React.Fragment, null,
|
|
14
15
|
React.createElement("path", { d: "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" }),
|
|
@@ -281,17 +282,19 @@ const ZoomContainer = ({ slide, offset, rect, render, carousel, animation, zoom:
|
|
|
281
282
|
}
|
|
282
283
|
}, [changeZoom, changeOffsets]);
|
|
283
284
|
const onWheel = React.useCallback((event) => {
|
|
284
|
-
const { state: { zoom }, zoomProps: { wheelZoomDistanceFactor }, } = refs.current;
|
|
285
|
-
if (event.ctrlKey) {
|
|
286
|
-
event.stopPropagation();
|
|
285
|
+
const { state: { zoom }, zoomProps: { wheelZoomDistanceFactor, scrollToZoom }, } = refs.current;
|
|
286
|
+
if (event.ctrlKey || scrollToZoom) {
|
|
287
287
|
if (Math.abs(event.deltaY) > Math.abs(event.deltaX)) {
|
|
288
|
+
event.stopPropagation();
|
|
288
289
|
changeZoom(zoom * (1 - event.deltaY / wheelZoomDistanceFactor), true, ...translateCoordinates(event));
|
|
290
|
+
return;
|
|
289
291
|
}
|
|
290
|
-
return;
|
|
291
292
|
}
|
|
292
293
|
if (zoom > 1) {
|
|
293
294
|
event.stopPropagation();
|
|
294
|
-
|
|
295
|
+
if (!scrollToZoom) {
|
|
296
|
+
changeOffsets(event.deltaX, event.deltaY);
|
|
297
|
+
}
|
|
295
298
|
}
|
|
296
299
|
}, [changeZoom, changeOffsets, translateCoordinates]);
|
|
297
300
|
const clearPointer = React.useCallback((event) => {
|
package/dist/types.d.ts
CHANGED
|
@@ -99,6 +99,8 @@ export interface Render {
|
|
|
99
99
|
export interface Callbacks {
|
|
100
100
|
/** a callback called when a slide becomes active */
|
|
101
101
|
view?: (index: number) => void;
|
|
102
|
+
/** a callback called when a slide is clicked */
|
|
103
|
+
click?: (index: number) => void;
|
|
102
104
|
/** a callback called when the portal starts opening */
|
|
103
105
|
entering?: () => void;
|
|
104
106
|
/** a callback called when the portal opens */
|