yet-another-react-lightbox 3.5.3 → 3.6.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/index.d.ts +240 -4
- package/dist/index.js +1317 -4
- package/dist/plugins/captions/captions.css +1 -33
- package/dist/plugins/captions/captions.css.d.ts +2 -0
- package/dist/plugins/captions/index.d.ts +8 -4
- package/dist/plugins/captions/index.js +104 -3
- package/dist/plugins/counter/counter.css +1 -16
- package/dist/plugins/counter/counter.css.d.ts +2 -0
- package/dist/plugins/counter/index.d.ts +8 -3
- package/dist/plugins/counter/index.js +18 -2
- package/dist/plugins/download/index.d.ts +6 -3
- package/dist/plugins/download/index.js +90 -3
- package/dist/plugins/fullscreen/index.d.ts +8 -4
- package/dist/plugins/fullscreen/index.js +128 -3
- package/dist/plugins/index.d.ts +9 -9
- package/dist/plugins/index.js +9 -9
- package/dist/plugins/inline/index.d.ts +8 -3
- package/dist/plugins/inline/index.js +26 -2
- package/dist/plugins/slideshow/index.d.ts +8 -4
- package/dist/plugins/slideshow/index.js +113 -3
- package/dist/plugins/thumbnails/index.d.ts +7 -4
- package/dist/plugins/thumbnails/index.js +262 -3
- package/dist/plugins/thumbnails/thumbnails.css +1 -139
- package/dist/plugins/thumbnails/thumbnails.css.d.ts +2 -0
- package/dist/plugins/video/index.d.ts +7 -2
- package/dist/plugins/video/index.js +109 -2
- package/dist/plugins/zoom/index.d.ts +7 -4
- package/dist/plugins/zoom/index.js +499 -3
- package/dist/styles.css +1 -281
- package/dist/styles.css.d.ts +2 -0
- package/dist/types.d.ts +123 -47
- package/dist/types.js +51 -1
- package/package.json +34 -10
- package/dist/Lightbox.d.ts +0 -4
- package/dist/Lightbox.js +0 -46
- package/dist/core/components/IconButton.d.ts +0 -7
- package/dist/core/components/IconButton.js +0 -8
- package/dist/core/components/Icons.d.ts +0 -29
- package/dist/core/components/Icons.js +0 -27
- package/dist/core/components/ImageSlide.d.ts +0 -13
- package/dist/core/components/ImageSlide.js +0 -68
- package/dist/core/components/index.d.ts +0 -3
- package/dist/core/components/index.js +0 -3
- package/dist/core/config.d.ts +0 -7
- package/dist/core/config.js +0 -93
- package/dist/core/consts.d.ts +0 -50
- package/dist/core/consts.js +0 -49
- package/dist/core/contexts/Events.d.ts +0 -17
- package/dist/core/contexts/Events.js +0 -29
- package/dist/core/contexts/LightboxProps.d.ts +0 -6
- package/dist/core/contexts/LightboxProps.js +0 -7
- package/dist/core/contexts/LightboxState.d.ts +0 -27
- package/dist/core/contexts/LightboxState.js +0 -49
- package/dist/core/contexts/Timeouts.d.ts +0 -8
- package/dist/core/contexts/Timeouts.js +0 -32
- package/dist/core/contexts/index.d.ts +0 -4
- package/dist/core/contexts/index.js +0 -4
- package/dist/core/hooks/index.d.ts +0 -11
- package/dist/core/hooks/index.js +0 -11
- package/dist/core/hooks/useAnimation.d.ts +0 -15
- package/dist/core/hooks/useAnimation.js +0 -57
- package/dist/core/hooks/useContainerRect.d.ts +0 -7
- package/dist/core/hooks/useContainerRect.js +0 -36
- package/dist/core/hooks/useDelay.d.ts +0 -1
- package/dist/core/hooks/useDelay.js +0 -10
- package/dist/core/hooks/useEventCallback.d.ts +0 -1
- package/dist/core/hooks/useEventCallback.js +0 -9
- package/dist/core/hooks/useForkRef.d.ts +0 -3
- package/dist/core/hooks/useForkRef.js +0 -17
- package/dist/core/hooks/useLayoutEffect.d.ts +0 -2
- package/dist/core/hooks/useLayoutEffect.js +0 -3
- package/dist/core/hooks/useLoseFocus.d.ts +0 -4
- package/dist/core/hooks/useLoseFocus.js +0 -19
- package/dist/core/hooks/useMotionPreference.d.ts +0 -1
- package/dist/core/hooks/useMotionPreference.js +0 -13
- package/dist/core/hooks/useRTL.d.ts +0 -1
- package/dist/core/hooks/useRTL.js +0 -9
- package/dist/core/hooks/useSensors.d.ts +0 -14
- package/dist/core/hooks/useSensors.js +0 -38
- package/dist/core/hooks/useThrottle.d.ts +0 -1
- package/dist/core/hooks/useThrottle.js +0 -16
- package/dist/core/index.d.ts +0 -7
- package/dist/core/index.js +0 -7
- package/dist/core/modules/Carousel.d.ts +0 -4
- package/dist/core/modules/Carousel.js +0 -72
- package/dist/core/modules/Controller.d.ts +0 -31
- package/dist/core/modules/Controller.js +0 -215
- package/dist/core/modules/Navigation.d.ts +0 -13
- package/dist/core/modules/Navigation.js +0 -35
- package/dist/core/modules/NoScroll.d.ts +0 -4
- package/dist/core/modules/NoScroll.js +0 -52
- package/dist/core/modules/Portal.d.ts +0 -4
- package/dist/core/modules/Portal.js +0 -92
- package/dist/core/modules/Root.d.ts +0 -4
- package/dist/core/modules/Root.js +0 -7
- package/dist/core/modules/Toolbar.d.ts +0 -4
- package/dist/core/modules/Toolbar.js +0 -25
- package/dist/core/modules/controller/index.d.ts +0 -8
- package/dist/core/modules/controller/index.js +0 -9
- package/dist/core/modules/controller/usePointerSwipe.d.ts +0 -2
- package/dist/core/modules/controller/usePointerSwipe.js +0 -72
- package/dist/core/modules/controller/usePreventSwipeNavigation.d.ts +0 -3
- package/dist/core/modules/controller/usePreventSwipeNavigation.js +0 -20
- package/dist/core/modules/controller/useWheelSwipe.d.ts +0 -3
- package/dist/core/modules/controller/useWheelSwipe.js +0 -92
- package/dist/core/modules/index.d.ts +0 -7
- package/dist/core/modules/index.js +0 -7
- package/dist/core/utils.d.ts +0 -31
- package/dist/core/utils.js +0 -64
- package/dist/plugins/captions/Captions.d.ts +0 -3
- package/dist/plugins/captions/Captions.js +0 -25
- package/dist/plugins/captions/CaptionsButton.d.ts +0 -2
- package/dist/plugins/captions/CaptionsButton.js +0 -16
- package/dist/plugins/captions/CaptionsContext.d.ts +0 -5
- package/dist/plugins/captions/CaptionsContext.js +0 -16
- package/dist/plugins/captions/Description.d.ts +0 -4
- package/dist/plugins/captions/Description.js +0 -27
- package/dist/plugins/captions/Title.d.ts +0 -4
- package/dist/plugins/captions/Title.js +0 -16
- package/dist/plugins/captions/props.d.ts +0 -19
- package/dist/plugins/captions/props.js +0 -14
- package/dist/plugins/captions/utils.d.ts +0 -1
- package/dist/plugins/captions/utils.js +0 -2
- package/dist/plugins/counter/Counter.d.ts +0 -5
- package/dist/plugins/counter/Counter.js +0 -14
- package/dist/plugins/download/Download.d.ts +0 -2
- package/dist/plugins/download/Download.js +0 -9
- package/dist/plugins/download/DownloadButton.d.ts +0 -2
- package/dist/plugins/download/DownloadButton.js +0 -19
- package/dist/plugins/download/FileSaver.d.ts +0 -1
- package/dist/plugins/download/FileSaver.js +0 -60
- package/dist/plugins/fullscreen/Fullscreen.d.ts +0 -3
- package/dist/plugins/fullscreen/Fullscreen.js +0 -13
- package/dist/plugins/fullscreen/FullscreenButton.d.ts +0 -3
- package/dist/plugins/fullscreen/FullscreenButton.js +0 -16
- package/dist/plugins/fullscreen/FullscreenContext.d.ts +0 -5
- package/dist/plugins/fullscreen/FullscreenContext.js +0 -93
- package/dist/plugins/fullscreen/props.d.ts +0 -10
- package/dist/plugins/fullscreen/props.js +0 -8
- package/dist/plugins/inline/Inline.d.ts +0 -3
- package/dist/plugins/inline/Inline.js +0 -18
- package/dist/plugins/inline/InlineContainer.d.ts +0 -4
- package/dist/plugins/inline/InlineContainer.js +0 -5
- package/dist/plugins/slideshow/Slideshow.d.ts +0 -3
- package/dist/plugins/slideshow/Slideshow.js +0 -13
- package/dist/plugins/slideshow/SlideshowButton.d.ts +0 -2
- package/dist/plugins/slideshow/SlideshowButton.js +0 -14
- package/dist/plugins/slideshow/SlideshowContext.d.ts +0 -5
- package/dist/plugins/slideshow/SlideshowContext.js +0 -79
- package/dist/plugins/slideshow/props.d.ts +0 -12
- package/dist/plugins/slideshow/props.js +0 -9
- package/dist/plugins/thumbnails/Thumbnail.d.ts +0 -15
- package/dist/plugins/thumbnails/Thumbnail.js +0 -51
- package/dist/plugins/thumbnails/Thumbnails.d.ts +0 -3
- package/dist/plugins/thumbnails/Thumbnails.js +0 -22
- package/dist/plugins/thumbnails/ThumbnailsButton.d.ts +0 -2
- package/dist/plugins/thumbnails/ThumbnailsButton.js +0 -16
- package/dist/plugins/thumbnails/ThumbnailsContext.d.ts +0 -6
- package/dist/plugins/thumbnails/ThumbnailsContext.js +0 -24
- package/dist/plugins/thumbnails/ThumbnailsTrack.d.ts +0 -5
- package/dist/plugins/thumbnails/ThumbnailsTrack.js +0 -141
- package/dist/plugins/thumbnails/props.d.ts +0 -40
- package/dist/plugins/thumbnails/props.js +0 -21
- package/dist/plugins/thumbnails/utils.d.ts +0 -2
- package/dist/plugins/thumbnails/utils.js +0 -4
- package/dist/plugins/video/Video.d.ts +0 -3
- package/dist/plugins/video/Video.js +0 -21
- package/dist/plugins/video/VideoSlide.d.ts +0 -8
- package/dist/plugins/video/VideoSlide.js +0 -74
- package/dist/plugins/video/props.d.ts +0 -29
- package/dist/plugins/video/props.js +0 -13
- package/dist/plugins/zoom/ResponsiveImage.d.ts +0 -11
- package/dist/plugins/zoom/ResponsiveImage.js +0 -58
- package/dist/plugins/zoom/Zoom.d.ts +0 -3
- package/dist/plugins/zoom/Zoom.js +0 -18
- package/dist/plugins/zoom/ZoomButton.d.ts +0 -8
- package/dist/plugins/zoom/ZoomButton.js +0 -27
- package/dist/plugins/zoom/ZoomButtonsGroup.d.ts +0 -2
- package/dist/plugins/zoom/ZoomButtonsGroup.js +0 -22
- package/dist/plugins/zoom/ZoomController.d.ts +0 -12
- package/dist/plugins/zoom/ZoomController.js +0 -17
- package/dist/plugins/zoom/ZoomToolbarControl.d.ts +0 -2
- package/dist/plugins/zoom/ZoomToolbarControl.js +0 -12
- package/dist/plugins/zoom/ZoomWrapper.d.ts +0 -5
- package/dist/plugins/zoom/ZoomWrapper.js +0 -36
- package/dist/plugins/zoom/hooks/index.d.ts +0 -6
- package/dist/plugins/zoom/hooks/index.js +0 -6
- package/dist/plugins/zoom/hooks/useZoomAnimation.d.ts +0 -2
- package/dist/plugins/zoom/hooks/useZoomAnimation.js +0 -39
- package/dist/plugins/zoom/hooks/useZoomCallback.d.ts +0 -1
- package/dist/plugins/zoom/hooks/useZoomCallback.js +0 -12
- package/dist/plugins/zoom/hooks/useZoomImageRect.d.ts +0 -5
- package/dist/plugins/zoom/hooks/useZoomImageRect.js +0 -41
- package/dist/plugins/zoom/hooks/useZoomProps.d.ts +0 -13
- package/dist/plugins/zoom/hooks/useZoomProps.js +0 -6
- package/dist/plugins/zoom/hooks/useZoomSensors.d.ts +0 -3
- package/dist/plugins/zoom/hooks/useZoomSensors.js +0 -154
- package/dist/plugins/zoom/hooks/useZoomState.d.ts +0 -12
- package/dist/plugins/zoom/hooks/useZoomState.js +0 -63
- package/dist/plugins/zoom/props.d.ts +0 -25
- package/dist/plugins/zoom/props.js +0 -15
- package/dist/props.d.ts +0 -2
- package/dist/props.js +0 -38
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { cleanup, EVENT_ON_KEY_DOWN, EVENT_ON_POINTER_CANCEL, EVENT_ON_POINTER_DOWN, EVENT_ON_POINTER_LEAVE, EVENT_ON_POINTER_MOVE, EVENT_ON_POINTER_UP, EVENT_ON_WHEEL, useController, useEventCallback, useLightboxState, } from "../../../core/index.js";
|
|
3
|
-
import { useZoomProps } from "./useZoomProps.js";
|
|
4
|
-
function distance(pointerA, pointerB) {
|
|
5
|
-
return ((pointerA.clientX - pointerB.clientX) ** 2 + (pointerA.clientY - pointerB.clientY) ** 2) ** 0.5;
|
|
6
|
-
}
|
|
7
|
-
export function useZoomSensors(zoom, maxZoom, disabled, changeZoom, changeOffsets, zoomWrapperRef) {
|
|
8
|
-
const activePointers = React.useRef([]);
|
|
9
|
-
const lastPointerDown = React.useRef(0);
|
|
10
|
-
const pinchZoomDistance = React.useRef();
|
|
11
|
-
const { globalIndex } = useLightboxState();
|
|
12
|
-
const { containerRef, subscribeSensors } = useController();
|
|
13
|
-
const { keyboardMoveDistance, zoomInMultiplier, wheelZoomDistanceFactor, scrollToZoom, doubleTapDelay, doubleClickDelay, doubleClickMaxStops, pinchZoomDistanceFactor, } = useZoomProps();
|
|
14
|
-
const translateCoordinates = React.useCallback((event) => {
|
|
15
|
-
if (containerRef.current) {
|
|
16
|
-
const { pageX, pageY } = event;
|
|
17
|
-
const { scrollX, scrollY } = window;
|
|
18
|
-
const { left, top, width, height } = containerRef.current.getBoundingClientRect();
|
|
19
|
-
return [pageX - left - scrollX - width / 2, pageY - top - scrollY - height / 2];
|
|
20
|
-
}
|
|
21
|
-
return [];
|
|
22
|
-
}, [containerRef]);
|
|
23
|
-
const onKeyDown = useEventCallback((event) => {
|
|
24
|
-
const preventDefault = () => {
|
|
25
|
-
event.preventDefault();
|
|
26
|
-
event.stopPropagation();
|
|
27
|
-
};
|
|
28
|
-
if (zoom > 1) {
|
|
29
|
-
const move = (deltaX, deltaY) => {
|
|
30
|
-
preventDefault();
|
|
31
|
-
changeOffsets(deltaX, deltaY);
|
|
32
|
-
};
|
|
33
|
-
if (event.key === "ArrowDown") {
|
|
34
|
-
move(0, keyboardMoveDistance);
|
|
35
|
-
}
|
|
36
|
-
else if (event.key === "ArrowUp") {
|
|
37
|
-
move(0, -keyboardMoveDistance);
|
|
38
|
-
}
|
|
39
|
-
else if (event.key === "ArrowLeft") {
|
|
40
|
-
move(-keyboardMoveDistance, 0);
|
|
41
|
-
}
|
|
42
|
-
else if (event.key === "ArrowRight") {
|
|
43
|
-
move(keyboardMoveDistance, 0);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const handleChangeZoom = (zoomValue) => {
|
|
47
|
-
preventDefault();
|
|
48
|
-
changeZoom(zoomValue);
|
|
49
|
-
};
|
|
50
|
-
const hasMeta = () => event.getModifierState("Meta");
|
|
51
|
-
if (event.key === "+" || (event.key === "=" && hasMeta())) {
|
|
52
|
-
handleChangeZoom(zoom * zoomInMultiplier);
|
|
53
|
-
}
|
|
54
|
-
else if (event.key === "-" || (event.key === "_" && hasMeta())) {
|
|
55
|
-
handleChangeZoom(zoom / zoomInMultiplier);
|
|
56
|
-
}
|
|
57
|
-
else if (event.key === "0" && hasMeta()) {
|
|
58
|
-
handleChangeZoom(1);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
const onWheel = useEventCallback((event) => {
|
|
62
|
-
if (event.ctrlKey || scrollToZoom) {
|
|
63
|
-
if (Math.abs(event.deltaY) > Math.abs(event.deltaX)) {
|
|
64
|
-
event.stopPropagation();
|
|
65
|
-
changeZoom(zoom * (1 - event.deltaY / wheelZoomDistanceFactor), true, ...translateCoordinates(event));
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (zoom > 1) {
|
|
70
|
-
event.stopPropagation();
|
|
71
|
-
if (!scrollToZoom) {
|
|
72
|
-
changeOffsets(event.deltaX, event.deltaY);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
const clearPointer = React.useCallback((event) => {
|
|
77
|
-
const pointers = activePointers.current;
|
|
78
|
-
pointers.splice(0, pointers.length, ...pointers.filter((p) => p.pointerId !== event.pointerId));
|
|
79
|
-
}, []);
|
|
80
|
-
const replacePointer = React.useCallback((event) => {
|
|
81
|
-
clearPointer(event);
|
|
82
|
-
event.persist();
|
|
83
|
-
activePointers.current.push(event);
|
|
84
|
-
}, [clearPointer]);
|
|
85
|
-
const onPointerDown = useEventCallback((event) => {
|
|
86
|
-
var _a;
|
|
87
|
-
const pointers = activePointers.current;
|
|
88
|
-
if (!((_a = zoomWrapperRef === null || zoomWrapperRef === void 0 ? void 0 : zoomWrapperRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.target))) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
if (zoom > 1) {
|
|
92
|
-
event.stopPropagation();
|
|
93
|
-
}
|
|
94
|
-
const { timeStamp } = event;
|
|
95
|
-
if (pointers.length === 0 &&
|
|
96
|
-
timeStamp - lastPointerDown.current < (event.pointerType === "touch" ? doubleTapDelay : doubleClickDelay)) {
|
|
97
|
-
lastPointerDown.current = 0;
|
|
98
|
-
changeZoom(zoom !== maxZoom ? zoom * Math.max(maxZoom ** (1 / doubleClickMaxStops), zoomInMultiplier) : 1, false, ...translateCoordinates(event));
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
lastPointerDown.current = timeStamp;
|
|
102
|
-
}
|
|
103
|
-
replacePointer(event);
|
|
104
|
-
if (pointers.length === 2) {
|
|
105
|
-
pinchZoomDistance.current = distance(pointers[0], pointers[1]);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
const onPointerMove = useEventCallback((event) => {
|
|
109
|
-
const pointers = activePointers.current;
|
|
110
|
-
const activePointer = pointers.find((p) => p.pointerId === event.pointerId);
|
|
111
|
-
if (pointers.length === 2 && pinchZoomDistance.current) {
|
|
112
|
-
event.stopPropagation();
|
|
113
|
-
replacePointer(event);
|
|
114
|
-
const currentDistance = distance(pointers[0], pointers[1]);
|
|
115
|
-
const delta = currentDistance - pinchZoomDistance.current;
|
|
116
|
-
if (Math.abs(delta) > 0) {
|
|
117
|
-
changeZoom(zoom * (1 + delta / pinchZoomDistanceFactor), true, ...pointers
|
|
118
|
-
.map((x) => translateCoordinates(x))
|
|
119
|
-
.reduce((acc, coordinate) => coordinate.map((x, i) => acc[i] + x / 2)));
|
|
120
|
-
pinchZoomDistance.current = currentDistance;
|
|
121
|
-
}
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (zoom > 1) {
|
|
125
|
-
event.stopPropagation();
|
|
126
|
-
if (activePointer) {
|
|
127
|
-
if (pointers.length === 1) {
|
|
128
|
-
changeOffsets((activePointer.clientX - event.clientX) / zoom, (activePointer.clientY - event.clientY) / zoom);
|
|
129
|
-
}
|
|
130
|
-
replacePointer(event);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
const onPointerUp = React.useCallback((event) => {
|
|
135
|
-
const pointers = activePointers.current;
|
|
136
|
-
if (pointers.length === 2 && pointers.find((p) => p.pointerId === event.pointerId)) {
|
|
137
|
-
pinchZoomDistance.current = undefined;
|
|
138
|
-
}
|
|
139
|
-
clearPointer(event);
|
|
140
|
-
}, [clearPointer]);
|
|
141
|
-
const cleanupSensors = React.useCallback(() => {
|
|
142
|
-
const pointers = activePointers.current;
|
|
143
|
-
pointers.splice(0, pointers.length);
|
|
144
|
-
lastPointerDown.current = 0;
|
|
145
|
-
pinchZoomDistance.current = undefined;
|
|
146
|
-
}, []);
|
|
147
|
-
React.useEffect(cleanupSensors, [globalIndex, cleanupSensors]);
|
|
148
|
-
React.useEffect(() => {
|
|
149
|
-
if (!disabled) {
|
|
150
|
-
return cleanup(cleanupSensors, subscribeSensors(EVENT_ON_KEY_DOWN, onKeyDown), subscribeSensors(EVENT_ON_WHEEL, onWheel), subscribeSensors(EVENT_ON_POINTER_DOWN, onPointerDown), subscribeSensors(EVENT_ON_POINTER_MOVE, onPointerMove), subscribeSensors(EVENT_ON_POINTER_UP, onPointerUp), subscribeSensors(EVENT_ON_POINTER_LEAVE, onPointerUp), subscribeSensors(EVENT_ON_POINTER_CANCEL, onPointerUp));
|
|
151
|
-
}
|
|
152
|
-
return () => { };
|
|
153
|
-
}, [disabled, subscribeSensors, cleanupSensors, onKeyDown, onWheel, onPointerDown, onPointerMove, onPointerUp]);
|
|
154
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { ContainerRect } from "../../../types.js";
|
|
3
|
-
export declare function useZoomState(imageRect: ContainerRect, maxZoom: number, zoomWrapperRef?: React.RefObject<HTMLDivElement>): {
|
|
4
|
-
zoom: number;
|
|
5
|
-
offsetX: number;
|
|
6
|
-
offsetY: number;
|
|
7
|
-
disabled: boolean;
|
|
8
|
-
changeOffsets: (dx?: number, dy?: number, targetZoom?: number) => void;
|
|
9
|
-
changeZoom: (value: number, rapid?: boolean, dx?: number, dy?: number) => void;
|
|
10
|
-
zoomIn: () => void;
|
|
11
|
-
zoomOut: () => void;
|
|
12
|
-
};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { isImageSlide, round, useController, useEventCallback, useLayoutEffect, useLightboxState, } from "../../../core/index.js";
|
|
3
|
-
import { useZoomProps } from "./useZoomProps.js";
|
|
4
|
-
import { useZoomAnimation } from "./useZoomAnimation.js";
|
|
5
|
-
function getCurrentSource(slides, currentIndex) {
|
|
6
|
-
if (currentIndex < slides.length) {
|
|
7
|
-
const slide = slides[currentIndex];
|
|
8
|
-
if (isImageSlide(slide))
|
|
9
|
-
return slide.src;
|
|
10
|
-
}
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
export function useZoomState(imageRect, maxZoom, zoomWrapperRef) {
|
|
14
|
-
const [zoom, setZoom] = React.useState(1);
|
|
15
|
-
const [offsetX, setOffsetX] = React.useState(0);
|
|
16
|
-
const [offsetY, setOffsetY] = React.useState(0);
|
|
17
|
-
const animate = useZoomAnimation(zoom, offsetX, offsetY, zoomWrapperRef);
|
|
18
|
-
const { slides, currentIndex, globalIndex } = useLightboxState();
|
|
19
|
-
const { containerRect, slideRect } = useController();
|
|
20
|
-
const { zoomInMultiplier } = useZoomProps();
|
|
21
|
-
const currentSource = getCurrentSource(slides, currentIndex);
|
|
22
|
-
const disabled = !currentSource || !(zoomWrapperRef === null || zoomWrapperRef === void 0 ? void 0 : zoomWrapperRef.current);
|
|
23
|
-
useLayoutEffect(() => {
|
|
24
|
-
setZoom(1);
|
|
25
|
-
setOffsetX(0);
|
|
26
|
-
setOffsetY(0);
|
|
27
|
-
}, [globalIndex, currentSource]);
|
|
28
|
-
const changeOffsets = React.useCallback((dx, dy, targetZoom) => {
|
|
29
|
-
const newZoom = targetZoom || zoom;
|
|
30
|
-
const newOffsetX = offsetX - (dx || 0);
|
|
31
|
-
const newOffsetY = offsetY - (dy || 0);
|
|
32
|
-
const maxOffsetX = (imageRect.width * newZoom - slideRect.width) / 2 / newZoom;
|
|
33
|
-
const maxOffsetY = (imageRect.height * newZoom - slideRect.height) / 2 / newZoom;
|
|
34
|
-
setOffsetX(Math.min(Math.abs(newOffsetX), Math.max(maxOffsetX, 0)) * Math.sign(newOffsetX));
|
|
35
|
-
setOffsetY(Math.min(Math.abs(newOffsetY), Math.max(maxOffsetY, 0)) * Math.sign(newOffsetY));
|
|
36
|
-
}, [zoom, offsetX, offsetY, slideRect, imageRect.width, imageRect.height]);
|
|
37
|
-
const changeZoom = React.useCallback((value, rapid, dx, dy) => {
|
|
38
|
-
const newZoom = round(Math.min(Math.max(value + 0.001 < maxZoom ? value : maxZoom, 1), maxZoom), 5);
|
|
39
|
-
if (newZoom === zoom)
|
|
40
|
-
return;
|
|
41
|
-
if (!rapid) {
|
|
42
|
-
animate();
|
|
43
|
-
}
|
|
44
|
-
changeOffsets(dx ? dx * (1 / zoom - 1 / newZoom) : 0, dy ? dy * (1 / zoom - 1 / newZoom) : 0, newZoom);
|
|
45
|
-
setZoom(newZoom);
|
|
46
|
-
}, [zoom, maxZoom, changeOffsets, animate]);
|
|
47
|
-
const handleControllerRectChange = useEventCallback(() => {
|
|
48
|
-
if (zoom > 1) {
|
|
49
|
-
if (zoom > maxZoom) {
|
|
50
|
-
changeZoom(maxZoom, true);
|
|
51
|
-
}
|
|
52
|
-
changeOffsets();
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
useLayoutEffect(handleControllerRectChange, [
|
|
56
|
-
containerRect.width,
|
|
57
|
-
containerRect.height,
|
|
58
|
-
handleControllerRectChange,
|
|
59
|
-
]);
|
|
60
|
-
const zoomIn = React.useCallback(() => changeZoom(zoom * zoomInMultiplier), [zoom, zoomInMultiplier, changeZoom]);
|
|
61
|
-
const zoomOut = React.useCallback(() => changeZoom(zoom / zoomInMultiplier), [zoom, zoomInMultiplier, changeZoom]);
|
|
62
|
-
return { zoom, offsetX, offsetY, disabled, changeOffsets, changeZoom, zoomIn, zoomOut };
|
|
63
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { LightboxProps } from "../../types.js";
|
|
3
|
-
export declare const defaultZoomProps: {
|
|
4
|
-
maxZoomPixelRatio: number;
|
|
5
|
-
zoomInMultiplier: number;
|
|
6
|
-
doubleTapDelay: number;
|
|
7
|
-
doubleClickDelay: number;
|
|
8
|
-
doubleClickMaxStops: number;
|
|
9
|
-
keyboardMoveDistance: number;
|
|
10
|
-
wheelZoomDistanceFactor: number;
|
|
11
|
-
pinchZoomDistanceFactor: number;
|
|
12
|
-
scrollToZoom: boolean;
|
|
13
|
-
};
|
|
14
|
-
export declare const resolveZoomProps: (zoom: LightboxProps["zoom"]) => {
|
|
15
|
-
ref?: import("react").ForwardedRef<import("../../types.js").ZoomRef> | undefined;
|
|
16
|
-
maxZoomPixelRatio: number;
|
|
17
|
-
zoomInMultiplier: number;
|
|
18
|
-
doubleTapDelay: number;
|
|
19
|
-
doubleClickDelay: number;
|
|
20
|
-
doubleClickMaxStops: number;
|
|
21
|
-
keyboardMoveDistance: number;
|
|
22
|
-
wheelZoomDistanceFactor: number;
|
|
23
|
-
pinchZoomDistanceFactor: number;
|
|
24
|
-
scrollToZoom: boolean;
|
|
25
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export const defaultZoomProps = {
|
|
2
|
-
maxZoomPixelRatio: 1,
|
|
3
|
-
zoomInMultiplier: 2,
|
|
4
|
-
doubleTapDelay: 300,
|
|
5
|
-
doubleClickDelay: 500,
|
|
6
|
-
doubleClickMaxStops: 2,
|
|
7
|
-
keyboardMoveDistance: 50,
|
|
8
|
-
wheelZoomDistanceFactor: 100,
|
|
9
|
-
pinchZoomDistanceFactor: 100,
|
|
10
|
-
scrollToZoom: false,
|
|
11
|
-
};
|
|
12
|
-
export const resolveZoomProps = (zoom) => ({
|
|
13
|
-
...defaultZoomProps,
|
|
14
|
-
...zoom,
|
|
15
|
-
});
|
package/dist/props.d.ts
DELETED
package/dist/props.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { ACTION_CLOSE, IMAGE_FIT_CONTAIN } from "./core/consts.js";
|
|
2
|
-
export const LightboxDefaultProps = {
|
|
3
|
-
open: false,
|
|
4
|
-
close: () => { },
|
|
5
|
-
index: 0,
|
|
6
|
-
slides: [],
|
|
7
|
-
render: {},
|
|
8
|
-
plugins: [],
|
|
9
|
-
toolbar: { buttons: [ACTION_CLOSE] },
|
|
10
|
-
labels: {},
|
|
11
|
-
animation: {
|
|
12
|
-
fade: 250,
|
|
13
|
-
swipe: 500,
|
|
14
|
-
easing: {
|
|
15
|
-
fade: "ease",
|
|
16
|
-
swipe: "ease-out",
|
|
17
|
-
navigation: "ease-in-out",
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
carousel: {
|
|
21
|
-
finite: false,
|
|
22
|
-
preload: 2,
|
|
23
|
-
padding: "16px",
|
|
24
|
-
spacing: "30%",
|
|
25
|
-
imageFit: IMAGE_FIT_CONTAIN,
|
|
26
|
-
},
|
|
27
|
-
controller: {
|
|
28
|
-
ref: null,
|
|
29
|
-
focus: true,
|
|
30
|
-
aria: false,
|
|
31
|
-
touchAction: "none",
|
|
32
|
-
closeOnBackdropClick: false,
|
|
33
|
-
},
|
|
34
|
-
portal: {},
|
|
35
|
-
on: {},
|
|
36
|
-
styles: {},
|
|
37
|
-
className: "",
|
|
38
|
-
};
|