yet-another-react-lightbox 3.5.4 → 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.
Files changed (203) hide show
  1. package/dist/index.d.ts +240 -4
  2. package/dist/index.js +1317 -4
  3. package/dist/plugins/captions/captions.css +1 -33
  4. package/dist/plugins/captions/captions.css.d.ts +2 -0
  5. package/dist/plugins/captions/index.d.ts +8 -4
  6. package/dist/plugins/captions/index.js +104 -3
  7. package/dist/plugins/counter/counter.css +1 -16
  8. package/dist/plugins/counter/counter.css.d.ts +2 -0
  9. package/dist/plugins/counter/index.d.ts +8 -3
  10. package/dist/plugins/counter/index.js +18 -2
  11. package/dist/plugins/download/index.d.ts +6 -3
  12. package/dist/plugins/download/index.js +90 -3
  13. package/dist/plugins/fullscreen/index.d.ts +8 -4
  14. package/dist/plugins/fullscreen/index.js +128 -3
  15. package/dist/plugins/index.d.ts +9 -9
  16. package/dist/plugins/index.js +9 -9
  17. package/dist/plugins/inline/index.d.ts +8 -3
  18. package/dist/plugins/inline/index.js +26 -2
  19. package/dist/plugins/slideshow/index.d.ts +8 -4
  20. package/dist/plugins/slideshow/index.js +113 -3
  21. package/dist/plugins/thumbnails/index.d.ts +7 -4
  22. package/dist/plugins/thumbnails/index.js +262 -3
  23. package/dist/plugins/thumbnails/thumbnails.css +1 -139
  24. package/dist/plugins/thumbnails/thumbnails.css.d.ts +2 -0
  25. package/dist/plugins/video/index.d.ts +7 -2
  26. package/dist/plugins/video/index.js +109 -2
  27. package/dist/plugins/zoom/index.d.ts +7 -4
  28. package/dist/plugins/zoom/index.js +499 -3
  29. package/dist/styles.css +1 -281
  30. package/dist/styles.css.d.ts +2 -0
  31. package/dist/types.d.ts +123 -47
  32. package/dist/types.js +51 -1
  33. package/package.json +34 -10
  34. package/dist/Lightbox.d.ts +0 -4
  35. package/dist/Lightbox.js +0 -46
  36. package/dist/core/components/IconButton.d.ts +0 -7
  37. package/dist/core/components/IconButton.js +0 -8
  38. package/dist/core/components/Icons.d.ts +0 -29
  39. package/dist/core/components/Icons.js +0 -27
  40. package/dist/core/components/ImageSlide.d.ts +0 -13
  41. package/dist/core/components/ImageSlide.js +0 -68
  42. package/dist/core/components/index.d.ts +0 -3
  43. package/dist/core/components/index.js +0 -3
  44. package/dist/core/config.d.ts +0 -7
  45. package/dist/core/config.js +0 -93
  46. package/dist/core/consts.d.ts +0 -50
  47. package/dist/core/consts.js +0 -49
  48. package/dist/core/contexts/Events.d.ts +0 -17
  49. package/dist/core/contexts/Events.js +0 -29
  50. package/dist/core/contexts/LightboxProps.d.ts +0 -6
  51. package/dist/core/contexts/LightboxProps.js +0 -7
  52. package/dist/core/contexts/LightboxState.d.ts +0 -27
  53. package/dist/core/contexts/LightboxState.js +0 -49
  54. package/dist/core/contexts/Timeouts.d.ts +0 -8
  55. package/dist/core/contexts/Timeouts.js +0 -32
  56. package/dist/core/contexts/index.d.ts +0 -4
  57. package/dist/core/contexts/index.js +0 -4
  58. package/dist/core/hooks/index.d.ts +0 -11
  59. package/dist/core/hooks/index.js +0 -11
  60. package/dist/core/hooks/useAnimation.d.ts +0 -15
  61. package/dist/core/hooks/useAnimation.js +0 -57
  62. package/dist/core/hooks/useContainerRect.d.ts +0 -7
  63. package/dist/core/hooks/useContainerRect.js +0 -36
  64. package/dist/core/hooks/useDelay.d.ts +0 -1
  65. package/dist/core/hooks/useDelay.js +0 -10
  66. package/dist/core/hooks/useEventCallback.d.ts +0 -1
  67. package/dist/core/hooks/useEventCallback.js +0 -9
  68. package/dist/core/hooks/useForkRef.d.ts +0 -3
  69. package/dist/core/hooks/useForkRef.js +0 -17
  70. package/dist/core/hooks/useLayoutEffect.d.ts +0 -2
  71. package/dist/core/hooks/useLayoutEffect.js +0 -3
  72. package/dist/core/hooks/useLoseFocus.d.ts +0 -4
  73. package/dist/core/hooks/useLoseFocus.js +0 -19
  74. package/dist/core/hooks/useMotionPreference.d.ts +0 -1
  75. package/dist/core/hooks/useMotionPreference.js +0 -13
  76. package/dist/core/hooks/useRTL.d.ts +0 -1
  77. package/dist/core/hooks/useRTL.js +0 -9
  78. package/dist/core/hooks/useSensors.d.ts +0 -14
  79. package/dist/core/hooks/useSensors.js +0 -38
  80. package/dist/core/hooks/useThrottle.d.ts +0 -1
  81. package/dist/core/hooks/useThrottle.js +0 -16
  82. package/dist/core/index.d.ts +0 -7
  83. package/dist/core/index.js +0 -7
  84. package/dist/core/modules/Carousel.d.ts +0 -4
  85. package/dist/core/modules/Carousel.js +0 -72
  86. package/dist/core/modules/Controller.d.ts +0 -31
  87. package/dist/core/modules/Controller.js +0 -215
  88. package/dist/core/modules/Navigation.d.ts +0 -13
  89. package/dist/core/modules/Navigation.js +0 -35
  90. package/dist/core/modules/NoScroll.d.ts +0 -4
  91. package/dist/core/modules/NoScroll.js +0 -52
  92. package/dist/core/modules/Portal.d.ts +0 -4
  93. package/dist/core/modules/Portal.js +0 -92
  94. package/dist/core/modules/Root.d.ts +0 -4
  95. package/dist/core/modules/Root.js +0 -7
  96. package/dist/core/modules/Toolbar.d.ts +0 -4
  97. package/dist/core/modules/Toolbar.js +0 -25
  98. package/dist/core/modules/controller/index.d.ts +0 -8
  99. package/dist/core/modules/controller/index.js +0 -9
  100. package/dist/core/modules/controller/usePointerSwipe.d.ts +0 -2
  101. package/dist/core/modules/controller/usePointerSwipe.js +0 -72
  102. package/dist/core/modules/controller/usePreventSwipeNavigation.d.ts +0 -3
  103. package/dist/core/modules/controller/usePreventSwipeNavigation.js +0 -20
  104. package/dist/core/modules/controller/useWheelSwipe.d.ts +0 -3
  105. package/dist/core/modules/controller/useWheelSwipe.js +0 -92
  106. package/dist/core/modules/index.d.ts +0 -7
  107. package/dist/core/modules/index.js +0 -7
  108. package/dist/core/utils.d.ts +0 -36
  109. package/dist/core/utils.js +0 -70
  110. package/dist/plugins/captions/Captions.d.ts +0 -3
  111. package/dist/plugins/captions/Captions.js +0 -25
  112. package/dist/plugins/captions/CaptionsButton.d.ts +0 -2
  113. package/dist/plugins/captions/CaptionsButton.js +0 -16
  114. package/dist/plugins/captions/CaptionsContext.d.ts +0 -5
  115. package/dist/plugins/captions/CaptionsContext.js +0 -16
  116. package/dist/plugins/captions/Description.d.ts +0 -4
  117. package/dist/plugins/captions/Description.js +0 -27
  118. package/dist/plugins/captions/Title.d.ts +0 -4
  119. package/dist/plugins/captions/Title.js +0 -16
  120. package/dist/plugins/captions/props.d.ts +0 -19
  121. package/dist/plugins/captions/props.js +0 -14
  122. package/dist/plugins/captions/utils.d.ts +0 -1
  123. package/dist/plugins/captions/utils.js +0 -2
  124. package/dist/plugins/counter/Counter.d.ts +0 -5
  125. package/dist/plugins/counter/Counter.js +0 -14
  126. package/dist/plugins/download/Download.d.ts +0 -2
  127. package/dist/plugins/download/Download.js +0 -9
  128. package/dist/plugins/download/DownloadButton.d.ts +0 -2
  129. package/dist/plugins/download/DownloadButton.js +0 -19
  130. package/dist/plugins/download/FileSaver.d.ts +0 -1
  131. package/dist/plugins/download/FileSaver.js +0 -60
  132. package/dist/plugins/fullscreen/Fullscreen.d.ts +0 -3
  133. package/dist/plugins/fullscreen/Fullscreen.js +0 -13
  134. package/dist/plugins/fullscreen/FullscreenButton.d.ts +0 -3
  135. package/dist/plugins/fullscreen/FullscreenButton.js +0 -16
  136. package/dist/plugins/fullscreen/FullscreenContext.d.ts +0 -5
  137. package/dist/plugins/fullscreen/FullscreenContext.js +0 -93
  138. package/dist/plugins/fullscreen/props.d.ts +0 -10
  139. package/dist/plugins/fullscreen/props.js +0 -8
  140. package/dist/plugins/inline/Inline.d.ts +0 -3
  141. package/dist/plugins/inline/Inline.js +0 -18
  142. package/dist/plugins/inline/InlineContainer.d.ts +0 -4
  143. package/dist/plugins/inline/InlineContainer.js +0 -5
  144. package/dist/plugins/slideshow/Slideshow.d.ts +0 -3
  145. package/dist/plugins/slideshow/Slideshow.js +0 -13
  146. package/dist/plugins/slideshow/SlideshowButton.d.ts +0 -2
  147. package/dist/plugins/slideshow/SlideshowButton.js +0 -14
  148. package/dist/plugins/slideshow/SlideshowContext.d.ts +0 -5
  149. package/dist/plugins/slideshow/SlideshowContext.js +0 -79
  150. package/dist/plugins/slideshow/props.d.ts +0 -12
  151. package/dist/plugins/slideshow/props.js +0 -9
  152. package/dist/plugins/thumbnails/Thumbnail.d.ts +0 -15
  153. package/dist/plugins/thumbnails/Thumbnail.js +0 -51
  154. package/dist/plugins/thumbnails/Thumbnails.d.ts +0 -3
  155. package/dist/plugins/thumbnails/Thumbnails.js +0 -22
  156. package/dist/plugins/thumbnails/ThumbnailsButton.d.ts +0 -2
  157. package/dist/plugins/thumbnails/ThumbnailsButton.js +0 -16
  158. package/dist/plugins/thumbnails/ThumbnailsContext.d.ts +0 -6
  159. package/dist/plugins/thumbnails/ThumbnailsContext.js +0 -24
  160. package/dist/plugins/thumbnails/ThumbnailsTrack.d.ts +0 -5
  161. package/dist/plugins/thumbnails/ThumbnailsTrack.js +0 -141
  162. package/dist/plugins/thumbnails/props.d.ts +0 -40
  163. package/dist/plugins/thumbnails/props.js +0 -21
  164. package/dist/plugins/thumbnails/utils.d.ts +0 -2
  165. package/dist/plugins/thumbnails/utils.js +0 -4
  166. package/dist/plugins/video/Video.d.ts +0 -3
  167. package/dist/plugins/video/Video.js +0 -21
  168. package/dist/plugins/video/VideoSlide.d.ts +0 -8
  169. package/dist/plugins/video/VideoSlide.js +0 -74
  170. package/dist/plugins/video/props.d.ts +0 -29
  171. package/dist/plugins/video/props.js +0 -13
  172. package/dist/plugins/zoom/ResponsiveImage.d.ts +0 -11
  173. package/dist/plugins/zoom/ResponsiveImage.js +0 -58
  174. package/dist/plugins/zoom/Zoom.d.ts +0 -3
  175. package/dist/plugins/zoom/Zoom.js +0 -18
  176. package/dist/plugins/zoom/ZoomButton.d.ts +0 -8
  177. package/dist/plugins/zoom/ZoomButton.js +0 -27
  178. package/dist/plugins/zoom/ZoomButtonsGroup.d.ts +0 -2
  179. package/dist/plugins/zoom/ZoomButtonsGroup.js +0 -22
  180. package/dist/plugins/zoom/ZoomController.d.ts +0 -12
  181. package/dist/plugins/zoom/ZoomController.js +0 -17
  182. package/dist/plugins/zoom/ZoomToolbarControl.d.ts +0 -2
  183. package/dist/plugins/zoom/ZoomToolbarControl.js +0 -12
  184. package/dist/plugins/zoom/ZoomWrapper.d.ts +0 -5
  185. package/dist/plugins/zoom/ZoomWrapper.js +0 -36
  186. package/dist/plugins/zoom/hooks/index.d.ts +0 -6
  187. package/dist/plugins/zoom/hooks/index.js +0 -6
  188. package/dist/plugins/zoom/hooks/useZoomAnimation.d.ts +0 -2
  189. package/dist/plugins/zoom/hooks/useZoomAnimation.js +0 -39
  190. package/dist/plugins/zoom/hooks/useZoomCallback.d.ts +0 -1
  191. package/dist/plugins/zoom/hooks/useZoomCallback.js +0 -12
  192. package/dist/plugins/zoom/hooks/useZoomImageRect.d.ts +0 -5
  193. package/dist/plugins/zoom/hooks/useZoomImageRect.js +0 -41
  194. package/dist/plugins/zoom/hooks/useZoomProps.d.ts +0 -13
  195. package/dist/plugins/zoom/hooks/useZoomProps.js +0 -6
  196. package/dist/plugins/zoom/hooks/useZoomSensors.d.ts +0 -3
  197. package/dist/plugins/zoom/hooks/useZoomSensors.js +0 -154
  198. package/dist/plugins/zoom/hooks/useZoomState.d.ts +0 -12
  199. package/dist/plugins/zoom/hooks/useZoomState.js +0 -63
  200. package/dist/plugins/zoom/props.d.ts +0 -25
  201. package/dist/plugins/zoom/props.js +0 -15
  202. package/dist/props.d.ts +0 -2
  203. package/dist/props.js +0 -38
@@ -1,21 +0,0 @@
1
- import { useLightboxProps } from "../../core/index.js";
2
- export const defaultThumbnailsProps = {
3
- ref: null,
4
- position: "bottom",
5
- width: 120,
6
- height: 80,
7
- border: 1,
8
- borderRadius: 4,
9
- padding: 4,
10
- gap: 16,
11
- imageFit: "contain",
12
- vignette: true,
13
- };
14
- export const resolveThumbnailsProps = (thumbnails) => ({
15
- ...defaultThumbnailsProps,
16
- ...thumbnails,
17
- });
18
- export function useThumbnailsProps() {
19
- const { thumbnails } = useLightboxProps();
20
- return resolveThumbnailsProps(thumbnails);
21
- }
@@ -1,2 +0,0 @@
1
- export declare const cssPrefix: (value?: string) => string;
2
- export declare const cssThumbnailPrefix: (value?: string) => string;
@@ -1,4 +0,0 @@
1
- import { composePrefix } from "../../core/utils.js";
2
- import { PLUGIN_THUMBNAILS } from "../../core/consts.js";
3
- export const cssPrefix = (value) => composePrefix(PLUGIN_THUMBNAILS, value);
4
- export const cssThumbnailPrefix = (value) => cssPrefix(composePrefix("thumbnail", value));
@@ -1,3 +0,0 @@
1
- import { PluginProps } from "../../types.js";
2
- /** Video plugin */
3
- export declare function Video({ augment }: PluginProps): void;
@@ -1,21 +0,0 @@
1
- import * as React from "react";
2
- import { resolveVideoProps } from "./props.js";
3
- import { VideoSlide } from "./VideoSlide.js";
4
- function isVideoSlide(slide) {
5
- return slide.type === "video";
6
- }
7
- export function Video({ augment }) {
8
- augment(({ render: { slide: renderSlide, ...restRender }, video, ...restProps }) => ({
9
- render: {
10
- slide: ({ slide, offset, rect }) => {
11
- if (isVideoSlide(slide)) {
12
- return (React.createElement(VideoSlide, { key: `${slide.sources.map((source) => source.src).join(" ")}`, slide: slide, offset: offset }));
13
- }
14
- return renderSlide === null || renderSlide === void 0 ? void 0 : renderSlide({ slide, offset, rect });
15
- },
16
- ...restRender,
17
- },
18
- video: resolveVideoProps(video),
19
- ...restProps,
20
- }));
21
- }
@@ -1,8 +0,0 @@
1
- import * as React from "react";
2
- import { SlideVideo } from "../../types.js";
3
- export type VideoSlideProps = {
4
- slide: SlideVideo;
5
- offset: number;
6
- };
7
- /** Video slide */
8
- export declare function VideoSlide({ slide, offset }: VideoSlideProps): React.JSX.Element;
@@ -1,74 +0,0 @@
1
- import * as React from "react";
2
- import { ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, CLASS_FLEX_CENTER, clsx, cssClass, useContainerRect, useEventCallback, useEvents, } from "../../core/index.js";
3
- import { useVideoProps } from "./props.js";
4
- export function VideoSlide({ slide, offset }) {
5
- const video = useVideoProps();
6
- const { publish } = useEvents();
7
- const { setContainerRef, containerRect } = useContainerRect();
8
- const videoRef = React.useRef(null);
9
- React.useEffect(() => {
10
- if (offset !== 0 && videoRef.current && !videoRef.current.paused) {
11
- videoRef.current.pause();
12
- }
13
- }, [offset]);
14
- React.useEffect(() => {
15
- if (offset === 0 && videoRef.current && (slide.autoPlay || video.autoPlay)) {
16
- publish(ACTIVE_SLIDE_LOADING);
17
- videoRef.current.play().catch(() => { });
18
- }
19
- }, [offset, video.autoPlay, slide.autoPlay, publish]);
20
- const handleVideoRef = useEventCallback((node) => {
21
- if (offset === 0 && (video.autoPlay || slide.autoPlay) && node.paused) {
22
- node.play().catch(() => { });
23
- }
24
- });
25
- const setVideoRef = React.useCallback((node) => {
26
- videoRef.current = node;
27
- if (node) {
28
- handleVideoRef(node);
29
- }
30
- }, [handleVideoRef]);
31
- const { width, height, poster, sources } = slide;
32
- const scaleWidthAndHeight = () => {
33
- const scalingProps = {};
34
- scalingProps.style = { maxWidth: "100%", maxHeight: "100%" };
35
- if (width && height && containerRect) {
36
- const widthBound = width / height > containerRect.width / containerRect.height;
37
- const elementWidth = widthBound ? containerRect.width : Math.round((containerRect.height / height) * width);
38
- const elementHeight = !widthBound
39
- ? containerRect.height
40
- : Math.round((containerRect.width / width) * height);
41
- scalingProps.width = elementWidth;
42
- scalingProps.height = elementHeight;
43
- scalingProps.style.width = elementWidth;
44
- scalingProps.style.height = elementHeight;
45
- }
46
- return scalingProps;
47
- };
48
- const resolveBoolean = (attr) => {
49
- if (slide[attr] === false)
50
- return null;
51
- if (slide[attr] === true)
52
- return { [attr]: true };
53
- if (video[attr] === false)
54
- return null;
55
- if (video[attr] === true)
56
- return { [attr]: true };
57
- return null;
58
- };
59
- const resolveString = (attr) => {
60
- if (video[attr] || slide[attr]) {
61
- return { [attr]: slide[attr] || video[attr] };
62
- }
63
- return null;
64
- };
65
- return (React.createElement(React.Fragment, null, sources && (React.createElement("div", { ref: setContainerRef, style: {
66
- width: "100%",
67
- height: "100%",
68
- ...(width ? { maxWidth: `${width}px` } : null),
69
- }, className: clsx(cssClass("video_container"), cssClass(CLASS_FLEX_CENTER)) }, containerRect && (React.createElement("video", { ref: setVideoRef, poster: poster, ...scaleWidthAndHeight(), ...resolveBoolean("controls"), ...resolveBoolean("playsInline"), ...resolveBoolean("loop"), ...resolveBoolean("muted"), ...resolveBoolean("playsInline"), ...resolveBoolean("disablePictureInPicture"), ...resolveBoolean("disableRemotePlayback"), ...resolveString("controlsList"), ...resolveString("crossOrigin"), ...resolveString("preload"), onPlay: () => {
70
- publish(ACTIVE_SLIDE_PLAYING);
71
- }, onEnded: () => {
72
- publish(ACTIVE_SLIDE_COMPLETE);
73
- } }, sources.map(({ src, type }, index) => (React.createElement("source", { key: index, src: src, type: type })))))))));
74
- }
@@ -1,29 +0,0 @@
1
- import { LightboxProps } from "../../types.js";
2
- export declare const defaultVideoProps: {
3
- controls: boolean;
4
- playsInline: boolean;
5
- };
6
- export declare const resolveVideoProps: (video: LightboxProps["video"]) => {
7
- autoPlay?: boolean | undefined;
8
- controls: boolean;
9
- controlsList?: string | undefined;
10
- crossOrigin?: string | undefined;
11
- preload?: string | undefined;
12
- loop?: boolean | undefined;
13
- muted?: boolean | undefined;
14
- playsInline: boolean;
15
- disablePictureInPicture?: boolean | undefined;
16
- disableRemotePlayback?: boolean | undefined;
17
- };
18
- export declare function useVideoProps(): {
19
- autoPlay?: boolean | undefined;
20
- controls: boolean;
21
- controlsList?: string | undefined;
22
- crossOrigin?: string | undefined;
23
- preload?: string | undefined;
24
- loop?: boolean | undefined;
25
- muted?: boolean | undefined;
26
- playsInline: boolean;
27
- disablePictureInPicture?: boolean | undefined;
28
- disableRemotePlayback?: boolean | undefined;
29
- };
@@ -1,13 +0,0 @@
1
- import { useLightboxProps } from "../../core/index.js";
2
- export const defaultVideoProps = {
3
- controls: true,
4
- playsInline: true,
5
- };
6
- export const resolveVideoProps = (video) => ({
7
- ...defaultVideoProps,
8
- ...video,
9
- });
10
- export function useVideoProps() {
11
- const { video } = useLightboxProps();
12
- return resolveVideoProps(video);
13
- }
@@ -1,11 +0,0 @@
1
- import * as React from "react";
2
- import { ImageSlideProps } from "../../core/index.js";
3
- import { ImageSource, SlideImage } from "../../types.js";
4
- export type ResponsiveImageSlide = Omit<SlideImage, "srcSet"> & {
5
- srcSet: [ImageSource, ...ImageSource[]];
6
- };
7
- export declare function isResponsiveImageSlide(slide: SlideImage): slide is ResponsiveImageSlide;
8
- export type ResponsiveImageProps = Omit<ImageSlideProps, "slide" | "rect"> & Required<Pick<ImageSlideProps, "rect">> & {
9
- slide: ResponsiveImageSlide;
10
- };
11
- export declare function ResponsiveImage(props: ResponsiveImageProps): React.JSX.Element;
@@ -1,58 +0,0 @@
1
- import * as React from "react";
2
- import { devicePixelRatio, ImageSlide, isImageFitCover, UNKNOWN_ACTION_TYPE, useEventCallback, useLayoutEffect, } from "../../core/index.js";
3
- export function isResponsiveImageSlide(slide) {
4
- var _a;
5
- return (((_a = slide.srcSet) === null || _a === void 0 ? void 0 : _a.length) || 0) > 0;
6
- }
7
- function reducer({ current, preload }, { type, source }) {
8
- switch (type) {
9
- case "fetch":
10
- if (!current) {
11
- return { current: source };
12
- }
13
- return { current, preload: source };
14
- case "done":
15
- if (source === preload) {
16
- return { current: source };
17
- }
18
- return { current, preload };
19
- default:
20
- throw new Error(UNKNOWN_ACTION_TYPE);
21
- }
22
- }
23
- export function ResponsiveImage(props) {
24
- var _a, _b;
25
- const [{ current, preload }, dispatch] = React.useReducer(reducer, {});
26
- const { slide: image, rect, imageFit, render } = props;
27
- const srcSet = image.srcSet.sort((a, b) => a.width - b.width);
28
- const width = (_a = image.width) !== null && _a !== void 0 ? _a : srcSet[srcSet.length - 1].width;
29
- const height = (_b = image.height) !== null && _b !== void 0 ? _b : srcSet[srcSet.length - 1].height;
30
- const cover = isImageFitCover(image, imageFit);
31
- const maxWidth = Math.max(...srcSet.map((x) => x.width));
32
- const targetWidth = Math.min((cover ? Math.max : Math.min)(rect.width, width * (rect.height / height)), maxWidth);
33
- const pixelDensity = devicePixelRatio();
34
- const handleResize = useEventCallback(() => {
35
- var _a;
36
- const targetSource = (_a = srcSet.find((x) => x.width >= targetWidth * pixelDensity)) !== null && _a !== void 0 ? _a : srcSet[srcSet.length - 1];
37
- if (!current || srcSet.findIndex((x) => x.src === current) < srcSet.findIndex((x) => x === targetSource)) {
38
- dispatch({ type: "fetch", source: targetSource.src });
39
- }
40
- });
41
- useLayoutEffect(handleResize, [rect.width, rect.height, pixelDensity, handleResize]);
42
- const handlePreload = useEventCallback((currentPreload) => dispatch({ type: "done", source: currentPreload }));
43
- const style = {
44
- WebkitTransform: "translateZ(0)",
45
- };
46
- if (!cover) {
47
- Object.assign(style, rect.width / rect.height < width / height
48
- ? { width: "100%", height: "auto" }
49
- : { width: "auto", height: "100%" });
50
- }
51
- return (React.createElement(React.Fragment, null,
52
- preload && preload !== current && (React.createElement(ImageSlide, { key: "preload", ...props, slide: { ...image, src: preload, srcSet: undefined }, style: { position: "absolute", visibility: "hidden", ...style }, onLoad: () => handlePreload(preload), render: {
53
- ...render,
54
- iconLoading: () => null,
55
- iconError: () => null,
56
- } })),
57
- current && (React.createElement(ImageSlide, { key: "current", ...props, slide: { ...image, src: current, srcSet: undefined }, style: style }))));
58
- }
@@ -1,3 +0,0 @@
1
- import { Plugin } from "../../types.js";
2
- /** Zoom plugin */
3
- export declare const Zoom: Plugin;
@@ -1,18 +0,0 @@
1
- import * as React from "react";
2
- import { addToolbarButton, createModule, isImageSlide, PLUGIN_ZOOM } from "../../core/index.js";
3
- import { resolveZoomProps } from "./props.js";
4
- import { ZoomContextProvider } from "./ZoomController.js";
5
- import { ZoomToolbarControl } from "./ZoomToolbarControl.js";
6
- import { ZoomWrapper } from "./ZoomWrapper.js";
7
- export const Zoom = ({ augment, addModule }) => {
8
- augment(({ toolbar, render, zoom, ...restProps }) => ({
9
- zoom: resolveZoomProps(zoom),
10
- toolbar: addToolbarButton(toolbar, PLUGIN_ZOOM, React.createElement(ZoomToolbarControl, null)),
11
- render: {
12
- ...render,
13
- slide: (props) => { var _a; return isImageSlide(props.slide) ? React.createElement(ZoomWrapper, { render: render, ...props }) : (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, props); },
14
- },
15
- ...restProps,
16
- }));
17
- addModule(createModule(PLUGIN_ZOOM, ZoomContextProvider));
18
- };
@@ -1,8 +0,0 @@
1
- import * as React from "react";
2
- /** Zoom button props */
3
- export type ZoomButtonProps = {
4
- zoomIn?: boolean;
5
- onLoseFocus: () => void;
6
- };
7
- /** Zoom button */
8
- export declare const ZoomButton: React.ForwardRefExoticComponent<ZoomButtonProps & React.RefAttributes<HTMLButtonElement>>;
@@ -1,27 +0,0 @@
1
- import * as React from "react";
2
- import { createIcon, IconButton, useLightboxProps } from "../../core/index.js";
3
- import { useZoom } from "./ZoomController.js";
4
- const ZoomInIcon = createIcon("ZoomIn", React.createElement(React.Fragment, null,
5
- 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" }),
6
- React.createElement("path", { d: "M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z" })));
7
- const ZoomOutIcon = createIcon("ZoomOut", 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 14zM7 9h5v1H7z" }));
8
- export const ZoomButton = React.forwardRef(function ZoomButton({ zoomIn, onLoseFocus }, ref) {
9
- const wasEnabled = React.useRef(false);
10
- const wasFocused = React.useRef(false);
11
- const { zoom, maxZoom, zoomIn: zoomInCallback, zoomOut: zoomOutCallback, disabled: zoomDisabled } = useZoom();
12
- const { render } = useLightboxProps();
13
- const disabled = zoomDisabled || (zoomIn ? zoom >= maxZoom : zoom <= 1);
14
- React.useEffect(() => {
15
- if (disabled && wasEnabled.current && wasFocused.current) {
16
- onLoseFocus();
17
- }
18
- if (!disabled) {
19
- wasEnabled.current = true;
20
- }
21
- }, [disabled, onLoseFocus]);
22
- return (React.createElement(IconButton, { ref: ref, disabled: disabled, label: zoomIn ? "Zoom in" : "Zoom out", icon: zoomIn ? ZoomInIcon : ZoomOutIcon, renderIcon: zoomIn ? render.iconZoomIn : render.iconZoomOut, onClick: zoomIn ? zoomInCallback : zoomOutCallback, onFocus: () => {
23
- wasFocused.current = true;
24
- }, onBlur: () => {
25
- wasFocused.current = false;
26
- } }));
27
- });
@@ -1,2 +0,0 @@
1
- import * as React from "react";
2
- export default function ZoomButtonsGroup(): React.JSX.Element;
@@ -1,22 +0,0 @@
1
- import * as React from "react";
2
- import { useController } from "../../core/index.js";
3
- import { ZoomButton } from "./ZoomButton.js";
4
- export default function ZoomButtonsGroup() {
5
- const zoomInRef = React.useRef(null);
6
- const zoomOutRef = React.useRef(null);
7
- const { focus } = useController();
8
- const focusSibling = React.useCallback((sibling) => {
9
- var _a, _b;
10
- if (!((_a = sibling.current) === null || _a === void 0 ? void 0 : _a.disabled)) {
11
- (_b = sibling.current) === null || _b === void 0 ? void 0 : _b.focus();
12
- }
13
- else {
14
- focus();
15
- }
16
- }, [focus]);
17
- const focusZoomIn = React.useCallback(() => focusSibling(zoomInRef), [focusSibling]);
18
- const focusZoomOut = React.useCallback(() => focusSibling(zoomOutRef), [focusSibling]);
19
- return (React.createElement(React.Fragment, null,
20
- React.createElement(ZoomButton, { zoomIn: true, ref: zoomInRef, onLoseFocus: focusZoomOut }),
21
- React.createElement(ZoomButton, { ref: zoomOutRef, onLoseFocus: focusZoomIn })));
22
- }
@@ -1,12 +0,0 @@
1
- import * as React from "react";
2
- import { ComponentProps, ContainerRect, ZoomRef } from "../../types.js";
3
- export type ActiveZoomWrapper = {
4
- zoomWrapperRef: React.RefObject<HTMLDivElement>;
5
- imageDimensions?: ContainerRect;
6
- };
7
- export type ZoomControllerContextType = ZoomRef & {
8
- setZoomWrapper: React.Dispatch<React.SetStateAction<ActiveZoomWrapper | undefined>>;
9
- };
10
- export declare const ZoomControllerContext: React.Context<ZoomControllerContextType | null>;
11
- export declare const useZoom: () => NonNullable<ZoomControllerContextType>;
12
- export declare function ZoomContextProvider({ children }: ComponentProps): React.JSX.Element;
@@ -1,17 +0,0 @@
1
- import * as React from "react";
2
- import { makeUseContext, useController } from "../../core/index.js";
3
- import { useZoomCallback, useZoomImageRect, useZoomProps, useZoomSensors, useZoomState } from "./hooks/index.js";
4
- export const ZoomControllerContext = React.createContext(null);
5
- export const useZoom = makeUseContext("useZoom", "ZoomControllerContext", ZoomControllerContext);
6
- export function ZoomContextProvider({ children }) {
7
- const [zoomWrapper, setZoomWrapper] = React.useState();
8
- const { slideRect } = useController();
9
- const { imageRect, maxZoom } = useZoomImageRect(slideRect, zoomWrapper === null || zoomWrapper === void 0 ? void 0 : zoomWrapper.imageDimensions);
10
- const { zoom, offsetX, offsetY, disabled, changeZoom, changeOffsets, zoomIn, zoomOut } = useZoomState(imageRect, maxZoom, zoomWrapper === null || zoomWrapper === void 0 ? void 0 : zoomWrapper.zoomWrapperRef);
11
- useZoomCallback(zoom, disabled);
12
- useZoomSensors(zoom, maxZoom, disabled, changeZoom, changeOffsets, zoomWrapper === null || zoomWrapper === void 0 ? void 0 : zoomWrapper.zoomWrapperRef);
13
- const zoomRef = React.useMemo(() => ({ zoom, maxZoom, offsetX, offsetY, disabled, zoomIn, zoomOut }), [zoom, maxZoom, offsetX, offsetY, disabled, zoomIn, zoomOut]);
14
- React.useImperativeHandle(useZoomProps().ref, () => zoomRef, [zoomRef]);
15
- const context = React.useMemo(() => ({ ...zoomRef, setZoomWrapper }), [zoomRef, setZoomWrapper]);
16
- return React.createElement(ZoomControllerContext.Provider, { value: context }, children);
17
- }
@@ -1,2 +0,0 @@
1
- import * as React from "react";
2
- export declare function ZoomToolbarControl(): React.JSX.Element;
@@ -1,12 +0,0 @@
1
- import * as React from "react";
2
- import { useLightboxProps } from "../../core/index.js";
3
- import ZoomButtonsGroup from "./ZoomButtonsGroup.js";
4
- import { useZoom } from "./ZoomController.js";
5
- export function ZoomToolbarControl() {
6
- const { render } = useLightboxProps();
7
- const zoomRef = useZoom();
8
- if (render.buttonZoom) {
9
- return React.createElement(React.Fragment, null, render.buttonZoom(zoomRef));
10
- }
11
- return React.createElement(ZoomButtonsGroup, null);
12
- }
@@ -1,5 +0,0 @@
1
- import * as React from "react";
2
- import { LightboxProps, RenderSlideProps } from "../../types.js";
3
- export type ZoomWrapperProps = Pick<LightboxProps, "render"> & RenderSlideProps;
4
- /** Zoom wrapper */
5
- export declare function ZoomWrapper({ render, slide, offset, rect }: ZoomWrapperProps): React.JSX.Element | null;
@@ -1,36 +0,0 @@
1
- import * as React from "react";
2
- import { CLASS_FLEX_CENTER, CLASS_FULLSIZE, clsx, cssClass, ImageSlide, isImageSlide, useLayoutEffect, useLightboxProps, useLightboxState, } from "../../core/index.js";
3
- import { useZoom } from "./ZoomController.js";
4
- import { isResponsiveImageSlide, ResponsiveImage } from "./ResponsiveImage.js";
5
- export function ZoomWrapper({ render, slide, offset, rect }) {
6
- var _a;
7
- const [imageDimensions, setImageDimensions] = React.useState();
8
- const zoomWrapperRef = React.useRef(null);
9
- const { zoom, maxZoom, offsetX, offsetY, setZoomWrapper } = useZoom();
10
- const { carousel, on } = useLightboxProps();
11
- const { currentIndex } = useLightboxState();
12
- useLayoutEffect(() => {
13
- if (offset === 0) {
14
- setZoomWrapper({ zoomWrapperRef, imageDimensions });
15
- return () => setZoomWrapper(undefined);
16
- }
17
- return () => { };
18
- }, [offset, imageDimensions, setZoomWrapper]);
19
- let rendered = (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, { slide, offset, rect, zoom, maxZoom });
20
- if (!rendered && isImageSlide(slide)) {
21
- const slideProps = {
22
- slide,
23
- offset,
24
- rect,
25
- render,
26
- imageFit: carousel.imageFit,
27
- onClick: offset === 0 ? () => { var _a; return (_a = on.click) === null || _a === void 0 ? void 0 : _a.call(on, { index: currentIndex }); } : undefined,
28
- };
29
- rendered = isResponsiveImageSlide(slide) ? (React.createElement(ResponsiveImage, { key: slide.src, ...slideProps, slide: slide, rect: offset === 0 ? { width: rect.width * zoom, height: rect.height * zoom } : rect })) : (React.createElement(ImageSlide, { key: slide.src, onLoad: (img) => setImageDimensions({ width: img.naturalWidth, height: img.naturalHeight }), ...slideProps }));
30
- }
31
- if (!rendered)
32
- return null;
33
- return (React.createElement("div", { ref: zoomWrapperRef, className: clsx(cssClass(CLASS_FULLSIZE), cssClass(CLASS_FLEX_CENTER)), style: offset === 0
34
- ? { transform: `scale(${zoom}) translateX(${offsetX}px) translateY(${offsetY}px)` }
35
- : undefined }, rendered));
36
- }
@@ -1,6 +0,0 @@
1
- export * from "./useZoomAnimation.js";
2
- export * from "./useZoomCallback.js";
3
- export * from "./useZoomImageRect.js";
4
- export * from "./useZoomProps.js";
5
- export * from "./useZoomSensors.js";
6
- export * from "./useZoomState.js";
@@ -1,6 +0,0 @@
1
- export * from "./useZoomAnimation.js";
2
- export * from "./useZoomCallback.js";
3
- export * from "./useZoomImageRect.js";
4
- export * from "./useZoomProps.js";
5
- export * from "./useZoomSensors.js";
6
- export * from "./useZoomState.js";
@@ -1,2 +0,0 @@
1
- import * as React from "react";
2
- export declare function useZoomAnimation(zoom: number, offsetX: number, offsetY: number, zoomWrapperRef?: React.RefObject<HTMLDivElement>): () => void;
@@ -1,39 +0,0 @@
1
- import * as React from "react";
2
- import { useEventCallback, useLayoutEffect, useLightboxProps, useMotionPreference } from "../../../core/index.js";
3
- export function useZoomAnimation(zoom, offsetX, offsetY, zoomWrapperRef) {
4
- const zoomAnimation = React.useRef();
5
- const zoomAnimationStart = React.useRef();
6
- const { zoom: zoomAnimationDuration } = useLightboxProps().animation;
7
- const reduceMotion = useMotionPreference();
8
- const playZoomAnimation = useEventCallback(() => {
9
- var _a, _b, _c;
10
- (_a = zoomAnimation.current) === null || _a === void 0 ? void 0 : _a.cancel();
11
- zoomAnimation.current = undefined;
12
- if (zoomAnimationStart.current && (zoomWrapperRef === null || zoomWrapperRef === void 0 ? void 0 : zoomWrapperRef.current)) {
13
- try {
14
- zoomAnimation.current = (_c = (_b = zoomWrapperRef.current).animate) === null || _c === void 0 ? void 0 : _c.call(_b, [
15
- { transform: zoomAnimationStart.current },
16
- { transform: `scale(${zoom}) translateX(${offsetX}px) translateY(${offsetY}px)` },
17
- ], {
18
- duration: !reduceMotion ? zoomAnimationDuration !== null && zoomAnimationDuration !== void 0 ? zoomAnimationDuration : 500 : 0,
19
- easing: zoomAnimation.current ? "ease-out" : "ease-in-out",
20
- });
21
- }
22
- catch (err) {
23
- console.error(err);
24
- }
25
- zoomAnimationStart.current = undefined;
26
- if (zoomAnimation.current) {
27
- zoomAnimation.current.onfinish = () => {
28
- zoomAnimation.current = undefined;
29
- };
30
- }
31
- }
32
- });
33
- useLayoutEffect(playZoomAnimation, [zoom, offsetX, offsetY, playZoomAnimation]);
34
- return React.useCallback(() => {
35
- zoomAnimationStart.current = (zoomWrapperRef === null || zoomWrapperRef === void 0 ? void 0 : zoomWrapperRef.current)
36
- ? window.getComputedStyle(zoomWrapperRef.current).transform
37
- : undefined;
38
- }, [zoomWrapperRef]);
39
- }
@@ -1 +0,0 @@
1
- export declare function useZoomCallback(zoom: number, disabled: boolean): void;
@@ -1,12 +0,0 @@
1
- import * as React from "react";
2
- import { useEventCallback, useLightboxProps } from "../../../core/index.js";
3
- export function useZoomCallback(zoom, disabled) {
4
- const { on } = useLightboxProps();
5
- const onZoomCallback = useEventCallback(() => {
6
- var _a;
7
- if (!disabled) {
8
- (_a = on.zoom) === null || _a === void 0 ? void 0 : _a.call(on, { zoom });
9
- }
10
- });
11
- React.useEffect(onZoomCallback, [zoom, onZoomCallback]);
12
- }
@@ -1,5 +0,0 @@
1
- import { ContainerRect } from "../../../types.js";
2
- export declare function useZoomImageRect(slideRect: ContainerRect, imageDimensions?: ContainerRect): {
3
- imageRect: ContainerRect;
4
- maxZoom: number;
5
- };
@@ -1,41 +0,0 @@
1
- import { isImageFitCover, isImageSlide, round, useLightboxProps, useLightboxState } from "../../../core/index.js";
2
- import { useZoomProps } from "./useZoomProps.js";
3
- export function useZoomImageRect(slideRect, imageDimensions) {
4
- var _a, _b;
5
- let imageRect = { width: 0, height: 0 };
6
- let maxImageRect = { width: 0, height: 0 };
7
- const { slides, currentIndex } = useLightboxState();
8
- const { imageFit } = useLightboxProps().carousel;
9
- const { maxZoomPixelRatio } = useZoomProps();
10
- if (slideRect && currentIndex < slides.length) {
11
- const slide = { ...slides[currentIndex], ...imageDimensions };
12
- if (isImageSlide(slide)) {
13
- const cover = isImageFitCover(slide, imageFit);
14
- const width = Math.max(...(((_a = slide.srcSet) === null || _a === void 0 ? void 0 : _a.map((x) => x.width)) || []).concat(slide.width ? [slide.width] : []));
15
- const height = Math.max(...(((_b = slide.srcSet) === null || _b === void 0 ? void 0 : _b.map((x) => x.height)) || []).concat(slide.height ? [slide.height] : []));
16
- if (width > 0 && height > 0 && slideRect.width > 0 && slideRect.height > 0) {
17
- maxImageRect = cover
18
- ? {
19
- width: Math.round(Math.min(width, (slideRect.width / slideRect.height) * height)),
20
- height: Math.round(Math.min(height, (slideRect.height / slideRect.width) * width)),
21
- }
22
- : { width, height };
23
- maxImageRect = {
24
- width: maxImageRect.width * maxZoomPixelRatio,
25
- height: maxImageRect.height * maxZoomPixelRatio,
26
- };
27
- imageRect = cover
28
- ? {
29
- width: Math.min(slideRect.width, maxImageRect.width, width),
30
- height: Math.min(slideRect.height, maxImageRect.height, height),
31
- }
32
- : {
33
- width: Math.round(Math.min(slideRect.width, (slideRect.height / height) * width, width)),
34
- height: Math.round(Math.min(slideRect.height, (slideRect.width / width) * height, height)),
35
- };
36
- }
37
- }
38
- }
39
- const maxZoom = imageRect.width ? Math.max(round(maxImageRect.width / imageRect.width, 5), 1) : 1;
40
- return { imageRect, maxZoom };
41
- }
@@ -1,13 +0,0 @@
1
- /// <reference types="react" />
2
- export declare function useZoomProps(): {
3
- ref?: import("react").ForwardedRef<import("../../../types.js").ZoomRef> | undefined;
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
- };
@@ -1,6 +0,0 @@
1
- import { useLightboxProps } from "../../../core/index.js";
2
- import { resolveZoomProps } from "../props.js";
3
- export function useZoomProps() {
4
- const { zoom } = useLightboxProps();
5
- return resolveZoomProps(zoom);
6
- }
@@ -1,3 +0,0 @@
1
- import * as React from "react";
2
- import { useZoomState } from "./useZoomState.js";
3
- export declare function useZoomSensors(zoom: number, maxZoom: number, disabled: boolean, changeZoom: ReturnType<typeof useZoomState>["changeZoom"], changeOffsets: ReturnType<typeof useZoomState>["changeOffsets"], zoomWrapperRef?: React.RefObject<HTMLDivElement>): void;