yet-another-react-lightbox 2.6.2 → 3.0.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/Lightbox.d.ts +1 -1
- package/dist/Lightbox.js +17 -13
- package/dist/core/components/IconButton.js +2 -2
- package/dist/core/components/ImageSlide.js +0 -3
- package/dist/core/config.d.ts +3 -3
- package/dist/core/config.js +18 -13
- package/dist/core/consts.d.ts +2 -4
- package/dist/core/consts.js +2 -4
- package/dist/core/contexts/Events.d.ts +3 -2
- package/dist/core/contexts/Events.js +3 -3
- package/dist/core/contexts/LightboxProps.d.ts +6 -0
- package/dist/core/contexts/LightboxProps.js +7 -0
- package/dist/core/contexts/LightboxState.d.ts +15 -15
- package/dist/core/contexts/LightboxState.js +33 -20
- package/dist/core/contexts/Timeouts.d.ts +1 -0
- package/dist/core/contexts/Timeouts.js +3 -3
- package/dist/core/contexts/index.d.ts +1 -0
- package/dist/core/contexts/index.js +1 -0
- package/dist/core/hooks/useAnimation.d.ts +4 -1
- package/dist/core/hooks/useAnimation.js +12 -3
- package/dist/core/hooks/useLoseFocus.js +3 -3
- package/dist/core/modules/Carousel.d.ts +1 -1
- package/dist/core/modules/Carousel.js +19 -24
- package/dist/core/modules/Controller.d.ts +15 -16
- package/dist/core/modules/Controller.js +68 -34
- package/dist/core/modules/Navigation.d.ts +4 -5
- package/dist/core/modules/Navigation.js +15 -12
- package/dist/core/modules/Portal.js +5 -4
- package/dist/core/modules/Root.d.ts +4 -0
- package/dist/core/modules/Root.js +7 -0
- package/dist/core/modules/Toolbar.d.ts +0 -6
- package/dist/core/modules/Toolbar.js +6 -8
- package/dist/core/modules/index.d.ts +1 -1
- package/dist/core/modules/index.js +1 -1
- package/dist/core/utils.d.ts +7 -10
- package/dist/core/utils.js +14 -14
- package/dist/plugins/captions/Captions.d.ts +2 -6
- package/dist/plugins/captions/Captions.js +17 -20
- package/dist/plugins/captions/Description.d.ts +2 -2
- package/dist/plugins/captions/Description.js +5 -3
- package/dist/plugins/captions/Title.js +2 -3
- package/dist/plugins/captions/captions.css +1 -0
- package/dist/plugins/captions/index.d.ts +2 -2
- package/dist/plugins/captions/props.d.ts +9 -0
- package/dist/plugins/captions/props.js +8 -0
- package/dist/plugins/captions/utils.d.ts +1 -1
- package/dist/plugins/captions/utils.js +1 -3
- package/dist/plugins/fullscreen/Fullscreen.d.ts +2 -2
- package/dist/plugins/fullscreen/Fullscreen.js +5 -3
- package/dist/plugins/fullscreen/FullscreenButton.js +8 -5
- package/dist/plugins/fullscreen/FullscreenContext.d.ts +5 -9
- package/dist/plugins/fullscreen/FullscreenContext.js +16 -26
- package/dist/plugins/fullscreen/index.d.ts +21 -10
- package/dist/plugins/fullscreen/props.d.ts +10 -0
- package/dist/plugins/fullscreen/props.js +8 -0
- package/dist/plugins/inline/Inline.d.ts +2 -2
- package/dist/plugins/inline/Inline.js +4 -7
- package/dist/plugins/inline/InlineContainer.d.ts +4 -0
- package/dist/plugins/inline/InlineContainer.js +5 -0
- package/dist/plugins/inline/index.d.ts +1 -1
- package/dist/plugins/slideshow/Slideshow.d.ts +2 -6
- package/dist/plugins/slideshow/Slideshow.js +7 -10
- package/dist/plugins/slideshow/SlideshowButton.js +7 -5
- package/dist/plugins/slideshow/SlideshowContext.d.ts +5 -9
- package/dist/plugins/slideshow/SlideshowContext.js +21 -12
- package/dist/plugins/slideshow/index.d.ts +16 -11
- package/dist/plugins/slideshow/props.d.ts +12 -0
- package/dist/plugins/slideshow/props.js +9 -0
- package/dist/plugins/thumbnails/Thumbnail.d.ts +3 -7
- package/dist/plugins/thumbnails/Thumbnail.js +7 -3
- package/dist/plugins/thumbnails/Thumbnails.d.ts +2 -13
- package/dist/plugins/thumbnails/Thumbnails.js +6 -19
- package/dist/plugins/thumbnails/ThumbnailsContainer.d.ts +1 -1
- package/dist/plugins/thumbnails/ThumbnailsContainer.js +10 -10
- package/dist/plugins/thumbnails/ThumbnailsTrack.d.ts +4 -6
- package/dist/plugins/thumbnails/ThumbnailsTrack.js +16 -14
- package/dist/plugins/thumbnails/index.d.ts +5 -5
- package/dist/plugins/thumbnails/props.d.ts +34 -0
- package/dist/plugins/thumbnails/props.js +20 -0
- package/dist/plugins/video/Video.d.ts +2 -6
- package/dist/plugins/video/Video.js +11 -11
- package/dist/plugins/video/VideoSlide.d.ts +1 -1
- package/dist/plugins/video/VideoSlide.js +3 -3
- package/dist/plugins/video/index.d.ts +39 -42
- package/dist/plugins/video/props.d.ts +29 -0
- package/dist/plugins/video/props.js +13 -0
- package/dist/plugins/zoom/ResponsiveImage.js +23 -15
- package/dist/plugins/zoom/Zoom.d.ts +0 -11
- package/dist/plugins/zoom/Zoom.js +11 -33
- package/dist/plugins/zoom/ZoomButton.d.ts +6 -5
- package/dist/plugins/zoom/ZoomButton.js +11 -33
- package/dist/plugins/zoom/ZoomButtonsGroup.d.ts +1 -4
- package/dist/plugins/zoom/ZoomButtonsGroup.js +6 -7
- package/dist/plugins/zoom/ZoomController.d.ts +12 -0
- package/dist/plugins/zoom/ZoomController.js +17 -0
- package/dist/plugins/zoom/ZoomToolbarControl.d.ts +2 -0
- package/dist/plugins/zoom/ZoomToolbarControl.js +12 -0
- package/dist/plugins/zoom/ZoomWrapper.d.ts +5 -0
- package/dist/plugins/zoom/ZoomWrapper.js +36 -0
- package/dist/plugins/zoom/hooks/index.d.ts +6 -0
- package/dist/plugins/zoom/hooks/index.js +6 -0
- package/dist/plugins/zoom/hooks/useZoomAnimation.d.ts +2 -0
- package/dist/plugins/zoom/hooks/useZoomAnimation.js +39 -0
- package/dist/plugins/zoom/hooks/useZoomCallback.d.ts +1 -0
- package/dist/plugins/zoom/hooks/useZoomCallback.js +12 -0
- package/dist/plugins/zoom/hooks/useZoomImageRect.d.ts +5 -0
- package/dist/plugins/zoom/hooks/useZoomImageRect.js +41 -0
- package/dist/plugins/zoom/hooks/useZoomProps.d.ts +13 -0
- package/dist/plugins/zoom/hooks/useZoomProps.js +6 -0
- package/dist/plugins/zoom/hooks/useZoomSensors.d.ts +3 -0
- package/dist/plugins/zoom/hooks/useZoomSensors.js +154 -0
- package/dist/plugins/zoom/hooks/useZoomState.d.ts +12 -0
- package/dist/plugins/zoom/hooks/useZoomState.js +63 -0
- package/dist/plugins/zoom/index.d.ts +37 -24
- package/dist/plugins/zoom/index.js +0 -2
- package/dist/plugins/zoom/props.d.ts +25 -0
- package/dist/plugins/zoom/props.js +15 -0
- package/dist/props.d.ts +0 -4
- package/dist/props.js +10 -5
- package/dist/types.d.ts +173 -117
- package/package.json +41 -11
- package/dist/core/modules/Core.d.ts +0 -4
- package/dist/core/modules/Core.js +0 -10
- package/dist/plugins/captions/CaptionsContext.d.ts +0 -7
- package/dist/plugins/captions/CaptionsContext.js +0 -11
- package/dist/plugins/zoom/ZoomContainer.d.ts +0 -9
- package/dist/plugins/zoom/ZoomContainer.js +0 -316
- package/dist/plugins/zoom/ZoomContext.d.ts +0 -11
- package/dist/plugins/zoom/ZoomContext.js +0 -20
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { CLASS_FLEX_CENTER, CLASS_FULLSIZE, cleanup, clsx, cssClass, 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, ImageSlide, isImageFitCover, isImageSlide, round, useContainerRect, useController, useEventCallback, useEvents, useLayoutEffect, useLightboxState, useMotionPreference, } from "../../core/index.js";
|
|
3
|
-
import { useZoom } from "./ZoomContext.js";
|
|
4
|
-
import { defaultZoomProps } from "./Zoom.js";
|
|
5
|
-
import { ACTION_ZOOM_IN, ACTION_ZOOM_OUT } from "./index.js";
|
|
6
|
-
import { isResponsiveImageSlide, ResponsiveImage } from "./ResponsiveImage.js";
|
|
7
|
-
function getSlideRects(slide, cover, maxZoomPixelRatio, rect) {
|
|
8
|
-
var _a, _b;
|
|
9
|
-
let slideRect = { width: 0, height: 0 };
|
|
10
|
-
let maxSlideRect = { width: 0, height: 0 };
|
|
11
|
-
if (rect && isImageSlide(slide)) {
|
|
12
|
-
const width = Math.max(...(((_a = slide.srcSet) === null || _a === void 0 ? void 0 : _a.map((x) => x.width)) || []).concat(slide.width ? [slide.width] : []));
|
|
13
|
-
const height = Math.max(...(((_b = slide.srcSet) === null || _b === void 0 ? void 0 : _b.map((x) => x.height)) || []).concat(slide.height ? [slide.height] : []));
|
|
14
|
-
if (width > 0 && height > 0 && rect.width > 0 && rect.height > 0) {
|
|
15
|
-
maxSlideRect = cover
|
|
16
|
-
? {
|
|
17
|
-
width: Math.round(Math.min(width, (rect.width / rect.height) * height)),
|
|
18
|
-
height: Math.round(Math.min(height, (rect.height / rect.width) * width)),
|
|
19
|
-
}
|
|
20
|
-
: { width, height };
|
|
21
|
-
maxSlideRect = {
|
|
22
|
-
width: maxSlideRect.width * maxZoomPixelRatio,
|
|
23
|
-
height: maxSlideRect.height * maxZoomPixelRatio,
|
|
24
|
-
};
|
|
25
|
-
slideRect = cover
|
|
26
|
-
? {
|
|
27
|
-
width: Math.min(rect.width, maxSlideRect.width, width),
|
|
28
|
-
height: Math.min(rect.height, maxSlideRect.height, height),
|
|
29
|
-
}
|
|
30
|
-
: {
|
|
31
|
-
width: Math.round(Math.min(rect.width, (rect.height / height) * width, width)),
|
|
32
|
-
height: Math.round(Math.min(rect.height, (rect.width / width) * height, height)),
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return { slideRect, maxSlideRect };
|
|
37
|
-
}
|
|
38
|
-
function distance(pointerA, pointerB) {
|
|
39
|
-
return ((pointerA.clientX - pointerB.clientX) ** 2 + (pointerA.clientY - pointerB.clientY) ** 2) ** 0.5;
|
|
40
|
-
}
|
|
41
|
-
export function ZoomContainer({ slide, offset, rect, render, carousel, animation, zoom: originalZoomProps, on, }) {
|
|
42
|
-
var _a;
|
|
43
|
-
const zoomProps = { ...defaultZoomProps, ...originalZoomProps };
|
|
44
|
-
const { currentIndex } = useLightboxState().state;
|
|
45
|
-
const [zoom, setZoom] = React.useState(1);
|
|
46
|
-
const [offsetX, setOffsetX] = React.useState(0);
|
|
47
|
-
const [offsetY, setOffsetY] = React.useState(0);
|
|
48
|
-
const [imageDimensions, setImageDimensions] = React.useState();
|
|
49
|
-
const activePointers = React.useRef([]);
|
|
50
|
-
const lastPointerDown = React.useRef(0);
|
|
51
|
-
const zoomAnimation = React.useRef();
|
|
52
|
-
const zoomAnimationStart = React.useRef();
|
|
53
|
-
const pinchZoomDistance = React.useRef();
|
|
54
|
-
const { isMinZoom, isMaxZoom, setIsMinZoom, setIsMaxZoom } = useZoom();
|
|
55
|
-
const { setContainerRef, containerRef, containerRect } = useContainerRect();
|
|
56
|
-
const { subscribeSensors, containerRef: controllerRef, containerRect: controllerRect } = useController();
|
|
57
|
-
const { subscribe } = useEvents();
|
|
58
|
-
const reduceMotion = useMotionPreference();
|
|
59
|
-
const { slideRect, maxSlideRect } = getSlideRects({ ...slide, ...imageDimensions }, isImageSlide(slide) && isImageFitCover(slide, carousel.imageFit), zoomProps.maxZoomPixelRatio, containerRect);
|
|
60
|
-
const maxZoom = slideRect.width ? Math.max(round(maxSlideRect.width / slideRect.width, 5), 1) : 1;
|
|
61
|
-
const changeOffsets = useEventCallback((dx, dy, targetZoom) => {
|
|
62
|
-
const newZoom = targetZoom || zoom;
|
|
63
|
-
const newOffsetX = offsetX - (dx || 0);
|
|
64
|
-
const newOffsetY = offsetY - (dy || 0);
|
|
65
|
-
const maxOffsetX = containerRect ? (slideRect.width * newZoom - containerRect.width) / 2 / newZoom : 0;
|
|
66
|
-
const maxOffsetY = containerRect ? (slideRect.height * newZoom - containerRect.height) / 2 / newZoom : 0;
|
|
67
|
-
setOffsetX(Math.min(Math.abs(newOffsetX), Math.max(maxOffsetX, 0)) * Math.sign(newOffsetX));
|
|
68
|
-
setOffsetY(Math.min(Math.abs(newOffsetY), Math.max(maxOffsetY, 0)) * Math.sign(newOffsetY));
|
|
69
|
-
});
|
|
70
|
-
const changeZoom = useEventCallback((value, rapid, dx, dy) => {
|
|
71
|
-
if (!containerRef.current || !containerRect)
|
|
72
|
-
return;
|
|
73
|
-
const newZoom = round(Math.min(Math.max(value + 0.001 < maxZoom ? value : maxZoom, 1), maxZoom), 5);
|
|
74
|
-
if (newZoom === zoom)
|
|
75
|
-
return;
|
|
76
|
-
if (!rapid) {
|
|
77
|
-
zoomAnimationStart.current = window.getComputedStyle(containerRef.current).transform;
|
|
78
|
-
}
|
|
79
|
-
changeOffsets(dx ? dx * (1 / zoom - 1 / newZoom) : 0, dy ? dy * (1 / zoom - 1 / newZoom) : 0, newZoom);
|
|
80
|
-
setZoom(newZoom);
|
|
81
|
-
});
|
|
82
|
-
const handleControllerRectChange = useEventCallback(() => {
|
|
83
|
-
if (zoom > 1) {
|
|
84
|
-
if (zoom > maxZoom) {
|
|
85
|
-
changeZoom(maxZoom, true);
|
|
86
|
-
}
|
|
87
|
-
changeOffsets();
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
useLayoutEffect(handleControllerRectChange, [
|
|
91
|
-
controllerRect.width,
|
|
92
|
-
controllerRect.height,
|
|
93
|
-
handleControllerRectChange,
|
|
94
|
-
]);
|
|
95
|
-
const handleZoomAndOffsetChange = useEventCallback(() => {
|
|
96
|
-
var _a, _b, _c, _d;
|
|
97
|
-
(_a = zoomAnimation.current) === null || _a === void 0 ? void 0 : _a.cancel();
|
|
98
|
-
if (zoomAnimationStart.current && containerRef.current) {
|
|
99
|
-
zoomAnimation.current = (_c = (_b = containerRef.current).animate) === null || _c === void 0 ? void 0 : _c.call(_b, [
|
|
100
|
-
{ transform: zoomAnimationStart.current },
|
|
101
|
-
{ transform: `scale(${zoom}) translateX(${offsetX}px) translateY(${offsetY}px)` },
|
|
102
|
-
], {
|
|
103
|
-
duration: !reduceMotion ? (_d = animation.zoom) !== null && _d !== void 0 ? _d : 500 : 0,
|
|
104
|
-
easing: zoomAnimation.current ? "ease-out" : "ease-in-out",
|
|
105
|
-
});
|
|
106
|
-
zoomAnimationStart.current = undefined;
|
|
107
|
-
if (zoomAnimation.current) {
|
|
108
|
-
zoomAnimation.current.onfinish = () => {
|
|
109
|
-
zoomAnimation.current = undefined;
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
useLayoutEffect(handleZoomAndOffsetChange, [zoom, offsetX, offsetY, handleZoomAndOffsetChange]);
|
|
115
|
-
useLayoutEffect(() => {
|
|
116
|
-
if (offset === 0) {
|
|
117
|
-
const resetZoom = () => {
|
|
118
|
-
setZoom(1);
|
|
119
|
-
setOffsetX(0);
|
|
120
|
-
setOffsetY(0);
|
|
121
|
-
setIsMinZoom(true);
|
|
122
|
-
setIsMaxZoom(false);
|
|
123
|
-
};
|
|
124
|
-
resetZoom();
|
|
125
|
-
return () => {
|
|
126
|
-
resetZoom();
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
return () => { };
|
|
130
|
-
}, [offset, setIsMinZoom, setIsMaxZoom]);
|
|
131
|
-
useLayoutEffect(() => {
|
|
132
|
-
if (offset === 0) {
|
|
133
|
-
const newMinZoom = zoom <= 1;
|
|
134
|
-
if (newMinZoom !== isMinZoom) {
|
|
135
|
-
setIsMinZoom(newMinZoom);
|
|
136
|
-
}
|
|
137
|
-
const newMaxZoom = zoom >= maxZoom;
|
|
138
|
-
if (newMaxZoom !== isMaxZoom) {
|
|
139
|
-
setIsMaxZoom(newMaxZoom);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}, [offset, zoom, maxZoom, isMinZoom, isMaxZoom, setIsMinZoom, setIsMaxZoom]);
|
|
143
|
-
const onZoomCallback = useEventCallback(() => {
|
|
144
|
-
var _a;
|
|
145
|
-
if (offset === 0) {
|
|
146
|
-
(_a = on.zoom) === null || _a === void 0 ? void 0 : _a.call(on, zoom);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
useLayoutEffect(onZoomCallback, [zoom, onZoomCallback]);
|
|
150
|
-
const translateCoordinates = React.useCallback((event) => {
|
|
151
|
-
if (controllerRef.current) {
|
|
152
|
-
const { pageX, pageY } = event;
|
|
153
|
-
const { scrollX, scrollY } = window;
|
|
154
|
-
const { left, top, width, height } = controllerRef.current.getBoundingClientRect();
|
|
155
|
-
return [pageX - left - scrollX - width / 2, pageY - top - scrollY - height / 2];
|
|
156
|
-
}
|
|
157
|
-
return [];
|
|
158
|
-
}, [controllerRef]);
|
|
159
|
-
const onKeyDown = useEventCallback((event) => {
|
|
160
|
-
const { keyboardMoveDistance, zoomInMultiplier } = zoomProps;
|
|
161
|
-
const preventDefault = () => {
|
|
162
|
-
event.preventDefault();
|
|
163
|
-
event.stopPropagation();
|
|
164
|
-
};
|
|
165
|
-
if (zoom > 1) {
|
|
166
|
-
const move = (deltaX, deltaY) => {
|
|
167
|
-
preventDefault();
|
|
168
|
-
changeOffsets(deltaX, deltaY);
|
|
169
|
-
};
|
|
170
|
-
if (event.key === "ArrowDown") {
|
|
171
|
-
move(0, keyboardMoveDistance);
|
|
172
|
-
}
|
|
173
|
-
else if (event.key === "ArrowUp") {
|
|
174
|
-
move(0, -keyboardMoveDistance);
|
|
175
|
-
}
|
|
176
|
-
else if (event.key === "ArrowLeft") {
|
|
177
|
-
move(-keyboardMoveDistance, 0);
|
|
178
|
-
}
|
|
179
|
-
else if (event.key === "ArrowRight") {
|
|
180
|
-
move(keyboardMoveDistance, 0);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
const handleChangeZoom = (zoomValue) => {
|
|
184
|
-
preventDefault();
|
|
185
|
-
changeZoom(zoomValue);
|
|
186
|
-
};
|
|
187
|
-
const hasMeta = () => event.getModifierState("Meta");
|
|
188
|
-
if (event.key === "+" || (event.key === "=" && hasMeta())) {
|
|
189
|
-
handleChangeZoom(zoom * zoomInMultiplier);
|
|
190
|
-
}
|
|
191
|
-
else if (event.key === "-" || (event.key === "_" && hasMeta())) {
|
|
192
|
-
handleChangeZoom(zoom / zoomInMultiplier);
|
|
193
|
-
}
|
|
194
|
-
else if (event.key === "0" && hasMeta()) {
|
|
195
|
-
handleChangeZoom(1);
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
const onWheel = useEventCallback((event) => {
|
|
199
|
-
const { wheelZoomDistanceFactor, scrollToZoom } = zoomProps;
|
|
200
|
-
if (event.ctrlKey || scrollToZoom) {
|
|
201
|
-
if (Math.abs(event.deltaY) > Math.abs(event.deltaX)) {
|
|
202
|
-
event.stopPropagation();
|
|
203
|
-
changeZoom(zoom * (1 - event.deltaY / wheelZoomDistanceFactor), true, ...translateCoordinates(event));
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (zoom > 1) {
|
|
208
|
-
event.stopPropagation();
|
|
209
|
-
if (!scrollToZoom) {
|
|
210
|
-
changeOffsets(event.deltaX, event.deltaY);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
const clearPointer = React.useCallback((event) => {
|
|
215
|
-
const pointers = activePointers.current;
|
|
216
|
-
pointers.splice(0, pointers.length, ...pointers.filter((p) => p.pointerId !== event.pointerId));
|
|
217
|
-
}, []);
|
|
218
|
-
const replacePointer = React.useCallback((event) => {
|
|
219
|
-
clearPointer(event);
|
|
220
|
-
event.persist();
|
|
221
|
-
activePointers.current.push(event);
|
|
222
|
-
}, [clearPointer]);
|
|
223
|
-
const onPointerDown = useEventCallback((event) => {
|
|
224
|
-
var _a;
|
|
225
|
-
const { doubleTapDelay, doubleClickDelay, zoomInMultiplier, doubleClickMaxStops } = zoomProps;
|
|
226
|
-
const pointers = activePointers.current;
|
|
227
|
-
if (!((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.target))) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
if (zoom > 1) {
|
|
231
|
-
event.stopPropagation();
|
|
232
|
-
}
|
|
233
|
-
const { timeStamp } = event;
|
|
234
|
-
if (pointers.length === 0 &&
|
|
235
|
-
timeStamp - lastPointerDown.current < (event.pointerType === "touch" ? doubleTapDelay : doubleClickDelay)) {
|
|
236
|
-
lastPointerDown.current = 0;
|
|
237
|
-
changeZoom(zoom !== maxZoom ? zoom * Math.max(maxZoom ** (1 / doubleClickMaxStops), zoomInMultiplier) : 1, false, ...translateCoordinates(event));
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
lastPointerDown.current = timeStamp;
|
|
241
|
-
}
|
|
242
|
-
replacePointer(event);
|
|
243
|
-
if (pointers.length === 2) {
|
|
244
|
-
pinchZoomDistance.current = distance(pointers[0], pointers[1]);
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
const onPointerMove = useEventCallback((event) => {
|
|
248
|
-
const pointers = activePointers.current;
|
|
249
|
-
const activePointer = pointers.find((p) => p.pointerId === event.pointerId);
|
|
250
|
-
if (pointers.length === 2 && pinchZoomDistance.current) {
|
|
251
|
-
event.stopPropagation();
|
|
252
|
-
replacePointer(event);
|
|
253
|
-
const currentDistance = distance(pointers[0], pointers[1]);
|
|
254
|
-
const delta = currentDistance - pinchZoomDistance.current;
|
|
255
|
-
if (Math.abs(delta) > 0) {
|
|
256
|
-
changeZoom(zoom * (1 + delta / zoomProps.pinchZoomDistanceFactor), true, ...pointers
|
|
257
|
-
.map((x) => translateCoordinates(x))
|
|
258
|
-
.reduce((acc, coordinate) => coordinate.map((x, i) => acc[i] + x / 2)));
|
|
259
|
-
pinchZoomDistance.current = currentDistance;
|
|
260
|
-
}
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
if (zoom > 1) {
|
|
264
|
-
event.stopPropagation();
|
|
265
|
-
if (activePointer) {
|
|
266
|
-
if (pointers.length === 1) {
|
|
267
|
-
changeOffsets((activePointer.clientX - event.clientX) / zoom, (activePointer.clientY - event.clientY) / zoom);
|
|
268
|
-
}
|
|
269
|
-
replacePointer(event);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
const onPointerUp = React.useCallback((event) => {
|
|
274
|
-
const pointers = activePointers.current;
|
|
275
|
-
if (pointers.length === 2 && pointers.find((p) => p.pointerId === event.pointerId)) {
|
|
276
|
-
pinchZoomDistance.current = undefined;
|
|
277
|
-
}
|
|
278
|
-
clearPointer(event);
|
|
279
|
-
}, [clearPointer]);
|
|
280
|
-
const handleZoomIn = useEventCallback(() => {
|
|
281
|
-
changeZoom(zoom * zoomProps.zoomInMultiplier);
|
|
282
|
-
});
|
|
283
|
-
const handleZoomOut = useEventCallback(() => {
|
|
284
|
-
changeZoom(zoom / zoomProps.zoomInMultiplier);
|
|
285
|
-
});
|
|
286
|
-
React.useEffect(() => offset === 0
|
|
287
|
-
? cleanup(subscribe(ACTION_ZOOM_IN, handleZoomIn), subscribe(ACTION_ZOOM_OUT, handleZoomOut), 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))
|
|
288
|
-
: () => { }, [
|
|
289
|
-
offset,
|
|
290
|
-
subscribe,
|
|
291
|
-
subscribeSensors,
|
|
292
|
-
onKeyDown,
|
|
293
|
-
onPointerDown,
|
|
294
|
-
onPointerMove,
|
|
295
|
-
onPointerUp,
|
|
296
|
-
onWheel,
|
|
297
|
-
changeZoom,
|
|
298
|
-
handleZoomIn,
|
|
299
|
-
handleZoomOut,
|
|
300
|
-
]);
|
|
301
|
-
let rendered = (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, slide, offset, rect);
|
|
302
|
-
if (!rendered && isImageSlide(slide)) {
|
|
303
|
-
const slideProps = {
|
|
304
|
-
slide,
|
|
305
|
-
offset,
|
|
306
|
-
rect,
|
|
307
|
-
render,
|
|
308
|
-
imageFit: carousel.imageFit,
|
|
309
|
-
onClick: offset === 0 ? () => { var _a; return (_a = on.click) === null || _a === void 0 ? void 0 : _a.call(on, currentIndex); } : undefined,
|
|
310
|
-
};
|
|
311
|
-
rendered = isResponsiveImageSlide(slide) ? (React.createElement(ResponsiveImage, { ...slideProps, slide: slide, rect: offset === 0 ? { width: rect.width * zoom, height: rect.height * zoom } : rect })) : (React.createElement(ImageSlide, { onLoad: (img) => setImageDimensions({ width: img.naturalWidth, height: img.naturalHeight }), ...slideProps }));
|
|
312
|
-
}
|
|
313
|
-
return rendered ? (React.createElement("div", { ref: setContainerRef, className: clsx(cssClass(CLASS_FULLSIZE), cssClass(CLASS_FLEX_CENTER)), ...(offset === 0
|
|
314
|
-
? { style: { transform: `scale(${zoom}) translateX(${offsetX}px) translateY(${offsetY}px)` } }
|
|
315
|
-
: null) }, rendered)) : null;
|
|
316
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { ComponentProps } from "../../types.js";
|
|
3
|
-
export type ZoomContextType = {
|
|
4
|
-
isMinZoom: boolean;
|
|
5
|
-
isMaxZoom: boolean;
|
|
6
|
-
isZoomSupported: boolean;
|
|
7
|
-
setIsMinZoom: (value: boolean) => void;
|
|
8
|
-
setIsMaxZoom: (value: boolean) => void;
|
|
9
|
-
};
|
|
10
|
-
export declare const useZoom: () => ZoomContextType;
|
|
11
|
-
export declare function ZoomContextProvider({ slides, children }: ComponentProps): JSX.Element;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { isImageSlide, makeUseContext, useEventCallback, useLayoutEffect, useLightboxState } from "../../core/index.js";
|
|
3
|
-
const ZoomContext = React.createContext(null);
|
|
4
|
-
export const useZoom = makeUseContext("useZoom", "ZoomContext", ZoomContext);
|
|
5
|
-
export function ZoomContextProvider({ slides, children }) {
|
|
6
|
-
const [isMinZoom, setIsMinZoom] = React.useState(false);
|
|
7
|
-
const [isMaxZoom, setIsMaxZoom] = React.useState(false);
|
|
8
|
-
const [isZoomSupported, setIsZoomSupported] = React.useState(false);
|
|
9
|
-
const { currentIndex } = useLightboxState().state;
|
|
10
|
-
const updateZoomSupported = useEventCallback(() => setIsZoomSupported(slides.length > currentIndex && isImageSlide(slides[currentIndex])));
|
|
11
|
-
useLayoutEffect(updateZoomSupported, [currentIndex, updateZoomSupported]);
|
|
12
|
-
const context = React.useMemo(() => ({
|
|
13
|
-
isMinZoom,
|
|
14
|
-
isMaxZoom,
|
|
15
|
-
isZoomSupported,
|
|
16
|
-
setIsMinZoom,
|
|
17
|
-
setIsMaxZoom,
|
|
18
|
-
}), [isMinZoom, isMaxZoom, isZoomSupported]);
|
|
19
|
-
return React.createElement(ZoomContext.Provider, { value: context }, children);
|
|
20
|
-
}
|