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,93 +0,0 @@
1
- import * as React from "react";
2
- import { CLASS_FULLSIZE, clsx, cssClass, makeUseContext, PLUGIN_FULLSCREEN, useEventCallback, useLayoutEffect, } from "../../core/index.js";
3
- import { resolveFullscreenProps } from "./props.js";
4
- export const FullscreenContext = React.createContext(null);
5
- export const useFullscreen = makeUseContext("useFullscreen", "FullscreenContext", FullscreenContext);
6
- export function FullscreenContextProvider({ fullscreen: fullscreenProps, children }) {
7
- const { auto, ref } = resolveFullscreenProps(fullscreenProps);
8
- const containerRef = React.useRef(null);
9
- const [fullscreen, setFullscreen] = React.useState(false);
10
- const [disabled, setDisabled] = React.useState();
11
- useLayoutEffect(() => {
12
- var _a, _b, _c, _d;
13
- setDisabled(!((_d = (_c = (_b = (_a = document.fullscreenEnabled) !== null && _a !== void 0 ? _a : document.webkitFullscreenEnabled) !== null && _b !== void 0 ? _b : document.mozFullScreenEnabled) !== null && _c !== void 0 ? _c : document.msFullscreenEnabled) !== null && _d !== void 0 ? _d : false));
14
- }, []);
15
- const getFullscreenElement = React.useCallback(() => {
16
- var _a, _b, _c;
17
- return (_c = (_b = (_a = document.fullscreenElement) !== null && _a !== void 0 ? _a : document.webkitFullscreenElement) !== null && _b !== void 0 ? _b : document.mozFullScreenElement) !== null && _c !== void 0 ? _c : document.msFullscreenElement;
18
- }, []);
19
- const enter = React.useCallback(() => {
20
- const container = containerRef.current;
21
- if (container) {
22
- try {
23
- if (container.requestFullscreen) {
24
- container.requestFullscreen().catch(() => { });
25
- }
26
- else if (container.webkitRequestFullscreen) {
27
- container.webkitRequestFullscreen();
28
- }
29
- else if (container.mozRequestFullScreen) {
30
- container.mozRequestFullScreen();
31
- }
32
- else if (container.msRequestFullscreen) {
33
- container.msRequestFullscreen();
34
- }
35
- }
36
- catch (err) {
37
- }
38
- }
39
- }, []);
40
- const exit = React.useCallback(() => {
41
- if (getFullscreenElement()) {
42
- try {
43
- if (document.exitFullscreen) {
44
- document.exitFullscreen().catch(() => { });
45
- }
46
- else if (document.webkitExitFullscreen) {
47
- document.webkitExitFullscreen();
48
- }
49
- else if (document.mozCancelFullScreen) {
50
- document.mozCancelFullScreen();
51
- }
52
- else if (document.msExitFullscreen) {
53
- document.msExitFullscreen();
54
- }
55
- }
56
- catch (err) {
57
- }
58
- }
59
- }, [getFullscreenElement]);
60
- const fullscreenChangeListener = React.useCallback(() => {
61
- if (getFullscreenElement() === containerRef.current) {
62
- setFullscreen(true);
63
- }
64
- else {
65
- setFullscreen(false);
66
- }
67
- }, [getFullscreenElement]);
68
- React.useEffect(() => {
69
- const events = ["fullscreenchange", "webkitfullscreenchange", "mozfullscreenchange", "MSFullscreenChange"];
70
- events.forEach((event) => {
71
- document.addEventListener(event, fullscreenChangeListener);
72
- });
73
- return () => {
74
- events.forEach((event) => {
75
- document.removeEventListener(event, fullscreenChangeListener);
76
- });
77
- };
78
- }, [fullscreenChangeListener]);
79
- const handleAutoFullscreen = useEventCallback(() => { var _a; return (_a = (auto ? enter : null)) === null || _a === void 0 ? void 0 : _a(); });
80
- React.useEffect(() => {
81
- handleAutoFullscreen();
82
- return () => exit();
83
- }, [handleAutoFullscreen, exit]);
84
- const context = React.useMemo(() => ({
85
- fullscreen,
86
- disabled,
87
- enter,
88
- exit,
89
- }), [fullscreen, disabled, enter, exit]);
90
- React.useImperativeHandle(ref, () => context, [context]);
91
- return (React.createElement("div", { ref: containerRef, className: clsx(cssClass(PLUGIN_FULLSCREEN), cssClass(CLASS_FULLSIZE)) },
92
- React.createElement(FullscreenContext.Provider, { value: context }, children)));
93
- }
@@ -1,10 +0,0 @@
1
- /// <reference types="react" />
2
- import { LightboxProps } from "../../types.js";
3
- export declare const defaultFullscreenProps: {
4
- auto: boolean;
5
- ref: null;
6
- };
7
- export declare const resolveFullscreenProps: (fullscreen: LightboxProps["fullscreen"]) => {
8
- ref: import("react").ForwardedRef<import("../../types.js").FullscreenRef>;
9
- auto: boolean;
10
- };
@@ -1,8 +0,0 @@
1
- export const defaultFullscreenProps = {
2
- auto: false,
3
- ref: null,
4
- };
5
- export const resolveFullscreenProps = (fullscreen) => ({
6
- ...defaultFullscreenProps,
7
- ...fullscreen,
8
- });
@@ -1,3 +0,0 @@
1
- import { PluginProps } from "../../types.js";
2
- /** Inline plugin */
3
- export declare function Inline({ augment, replace, remove }: PluginProps): void;
@@ -1,18 +0,0 @@
1
- import { ACTION_CLOSE, createModule, MODULE_NO_SCROLL, MODULE_PORTAL, PLUGIN_INLINE } from "../../core/index.js";
2
- import { InlineContainer } from "./InlineContainer.js";
3
- export function Inline({ augment, replace, remove }) {
4
- augment(({ toolbar: { buttons, ...restToolbar }, open, close, controller: { focus, aria, touchAction, ...restController }, className, ...restProps }) => ({
5
- open: true,
6
- close: () => { },
7
- toolbar: {
8
- buttons: buttons.filter((button) => button !== ACTION_CLOSE),
9
- ...restToolbar,
10
- },
11
- inline: { style: { width: "100%", height: "100%" }, className },
12
- controller: { focus: false, aria: true, touchAction: "pan-y", ...restController },
13
- className,
14
- ...restProps,
15
- }));
16
- remove(MODULE_NO_SCROLL);
17
- replace(MODULE_PORTAL, createModule(PLUGIN_INLINE, InlineContainer));
18
- }
@@ -1,4 +0,0 @@
1
- import * as React from "react";
2
- import { ComponentProps } from "../../types.js";
3
- /** Inline plugin container */
4
- export declare function InlineContainer({ inline: { className, ...rest }, children }: ComponentProps): React.JSX.Element;
@@ -1,5 +0,0 @@
1
- import * as React from "react";
2
- import { clsx, cssClass } from "../../core/index.js";
3
- export function InlineContainer({ inline: { className, ...rest } = {}, children }) {
4
- return (React.createElement("div", { className: clsx(cssClass("root"), cssClass("relative"), className), ...rest }, children));
5
- }
@@ -1,3 +0,0 @@
1
- import { PluginProps } from "../../types.js";
2
- /** Slideshow plugin */
3
- export declare function Slideshow({ augment, addModule }: PluginProps): void;
@@ -1,13 +0,0 @@
1
- import * as React from "react";
2
- import { addToolbarButton, createModule, PLUGIN_SLIDESHOW } from "../../core/index.js";
3
- import { resolveSlideshowProps } from "./props.js";
4
- import { SlideshowContextProvider } from "./SlideshowContext.js";
5
- import { SlideshowButton } from "./SlideshowButton.js";
6
- export function Slideshow({ augment, addModule }) {
7
- augment(({ slideshow, toolbar, ...restProps }) => ({
8
- toolbar: addToolbarButton(toolbar, PLUGIN_SLIDESHOW, React.createElement(SlideshowButton, null)),
9
- slideshow: resolveSlideshowProps(slideshow),
10
- ...restProps,
11
- }));
12
- addModule(createModule(PLUGIN_SLIDESHOW, SlideshowContextProvider));
13
- }
@@ -1,2 +0,0 @@
1
- import * as React from "react";
2
- export declare function SlideshowButton(): React.JSX.Element;
@@ -1,14 +0,0 @@
1
- import * as React from "react";
2
- import { createIcon, IconButton, useLightboxProps, useLoseFocus } from "../../core/index.js";
3
- import { useSlideshow } from "./SlideshowContext.js";
4
- const PlayIcon = createIcon("Play", React.createElement("path", { d: "M8 5v14l11-7z" }));
5
- const PauseIcon = createIcon("Pause", React.createElement("path", { d: "M6 19h4V5H6v14zm8-14v14h4V5h-4z" }));
6
- export function SlideshowButton() {
7
- const { playing, disabled, play, pause } = useSlideshow();
8
- const { render } = useLightboxProps();
9
- const focusListeners = useLoseFocus(disabled);
10
- if (render.buttonSlideshow) {
11
- return React.createElement(React.Fragment, null, render.buttonSlideshow({ playing, disabled, play, pause }));
12
- }
13
- return (React.createElement(IconButton, { label: playing ? "Pause" : "Play", icon: playing ? PauseIcon : PlayIcon, renderIcon: playing ? render.iconSlideshowPause : render.iconSlideshowPlay, onClick: playing ? pause : play, disabled: disabled, ...focusListeners }));
14
- }
@@ -1,5 +0,0 @@
1
- import * as React from "react";
2
- import { ComponentProps, SlideshowRef } from "../../types.js";
3
- export declare const SlideshowContext: React.Context<SlideshowRef | null>;
4
- export declare const useSlideshow: () => SlideshowRef;
5
- export declare function SlideshowContextProvider({ slideshow, carousel: { finite }, on, children }: ComponentProps): React.JSX.Element;
@@ -1,79 +0,0 @@
1
- import * as React from "react";
2
- import { ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, cleanup, makeUseContext, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLAYING, useController, useEventCallback, useEvents, useLightboxState, useTimeouts, } from "../../core/index.js";
3
- import { resolveSlideshowProps } from "./props.js";
4
- export const SlideshowContext = React.createContext(null);
5
- export const useSlideshow = makeUseContext("useSlideshow", "SlideshowContext", SlideshowContext);
6
- export function SlideshowContextProvider({ slideshow, carousel: { finite }, on, children }) {
7
- const { autoplay, delay, ref } = resolveSlideshowProps(slideshow);
8
- const wasPlaying = React.useRef(autoplay);
9
- const [playing, setPlaying] = React.useState(autoplay);
10
- const scheduler = React.useRef();
11
- const slideStatus = React.useRef();
12
- const { slides, currentIndex } = useLightboxState();
13
- const { setTimeout, clearTimeout } = useTimeouts();
14
- const { subscribe } = useEvents();
15
- const { next } = useController();
16
- const disabled = slides.length === 0 || (finite && currentIndex === slides.length - 1);
17
- const play = React.useCallback(() => {
18
- if (!playing && !disabled) {
19
- setPlaying(true);
20
- }
21
- }, [playing, disabled]);
22
- const pause = React.useCallback(() => {
23
- if (playing) {
24
- setPlaying(false);
25
- }
26
- }, [playing]);
27
- const cancelScheduler = React.useCallback(() => {
28
- clearTimeout(scheduler.current);
29
- scheduler.current = undefined;
30
- }, [clearTimeout]);
31
- const scheduleNextSlide = useEventCallback(() => {
32
- cancelScheduler();
33
- if (!playing ||
34
- disabled ||
35
- slideStatus.current === SLIDE_STATUS_LOADING ||
36
- slideStatus.current === SLIDE_STATUS_PLAYING) {
37
- return;
38
- }
39
- scheduler.current = setTimeout(() => {
40
- if (playing) {
41
- slideStatus.current = undefined;
42
- next();
43
- }
44
- }, delay);
45
- });
46
- React.useEffect(scheduleNextSlide, [currentIndex, playing, scheduleNextSlide]);
47
- React.useEffect(() => {
48
- if (playing && disabled) {
49
- setPlaying(false);
50
- }
51
- }, [currentIndex, playing, disabled]);
52
- const onSlideshowStart = useEventCallback(() => { var _a; return (_a = on.slideshowStart) === null || _a === void 0 ? void 0 : _a.call(on); });
53
- const onSlideshowStop = useEventCallback(() => { var _a; return (_a = on.slideshowStop) === null || _a === void 0 ? void 0 : _a.call(on); });
54
- React.useEffect(() => {
55
- if (playing) {
56
- onSlideshowStart();
57
- }
58
- else if (wasPlaying.current) {
59
- onSlideshowStop();
60
- }
61
- wasPlaying.current = playing;
62
- }, [playing, onSlideshowStart, onSlideshowStop]);
63
- React.useEffect(() => cleanup(cancelScheduler, subscribe(ACTIVE_SLIDE_LOADING, () => {
64
- slideStatus.current = SLIDE_STATUS_LOADING;
65
- cancelScheduler();
66
- }), subscribe(ACTIVE_SLIDE_PLAYING, () => {
67
- slideStatus.current = SLIDE_STATUS_PLAYING;
68
- cancelScheduler();
69
- }), subscribe(ACTIVE_SLIDE_ERROR, () => {
70
- slideStatus.current = SLIDE_STATUS_ERROR;
71
- scheduleNextSlide();
72
- }), subscribe(ACTIVE_SLIDE_COMPLETE, () => {
73
- slideStatus.current = SLIDE_STATUS_COMPLETE;
74
- scheduleNextSlide();
75
- })), [subscribe, cancelScheduler, scheduleNextSlide]);
76
- const context = React.useMemo(() => ({ playing, disabled, play, pause }), [playing, disabled, play, pause]);
77
- React.useImperativeHandle(ref, () => context, [context]);
78
- return React.createElement(SlideshowContext.Provider, { value: context }, children);
79
- }
@@ -1,12 +0,0 @@
1
- /// <reference types="react" />
2
- import { LightboxProps } from "../../types.js";
3
- export declare const defaultSlideshowProps: {
4
- autoplay: boolean;
5
- delay: number;
6
- ref: null;
7
- };
8
- export declare const resolveSlideshowProps: (slideshow: LightboxProps["slideshow"]) => {
9
- ref: import("react").ForwardedRef<import("../../types.js").SlideshowRef>;
10
- autoplay: boolean;
11
- delay: number;
12
- };
@@ -1,9 +0,0 @@
1
- export const defaultSlideshowProps = {
2
- autoplay: false,
3
- delay: 3000,
4
- ref: null,
5
- };
6
- export const resolveSlideshowProps = (slideshow) => ({
7
- ...defaultSlideshowProps,
8
- ...slideshow,
9
- });
@@ -1,15 +0,0 @@
1
- import * as React from "react";
2
- import { Slide } from "../../types.js";
3
- export type FadeSettings = {
4
- duration: number;
5
- delay: number;
6
- };
7
- export type ThumbnailProps = {
8
- slide: Slide | null;
9
- onClick: () => void;
10
- active: boolean;
11
- fadeIn?: FadeSettings;
12
- fadeOut?: FadeSettings;
13
- placeholder: boolean;
14
- };
15
- export declare function Thumbnail({ slide, onClick, active, fadeIn, fadeOut, placeholder }: ThumbnailProps): React.JSX.Element;
@@ -1,51 +0,0 @@
1
- import * as React from "react";
2
- import { CLASS_FLEX_CENTER, CLASS_FULLSIZE, clsx, createIcon, cssClass, cssVar, ELEMENT_ICON, ImageSlide, isImageSlide, makeComposePrefix, useLightboxProps, } from "../../core/index.js";
3
- import { cssPrefix, cssThumbnailPrefix } from "./utils.js";
4
- import { useThumbnailsProps } from "./props.js";
5
- const VideoThumbnailIcon = createIcon("VideoThumbnail", React.createElement("path", { d: "M10 16.5l6-4.5-6-4.5v9zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z" }));
6
- const UnknownThumbnailIcon = createIcon("UnknownThumbnail", React.createElement("path", { d: "M23 18V6c0-1.1-.9-2-2-2H3c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2zM8.5 12.5l2.5 3.01L14.5 11l4.5 6H5l3.5-4.5z" }));
7
- function renderThumbnail({ slide, render, rect, imageFit }) {
8
- var _a;
9
- const customThumbnail = (_a = render.thumbnail) === null || _a === void 0 ? void 0 : _a.call(render, { slide, render, rect, imageFit });
10
- if (customThumbnail) {
11
- return customThumbnail;
12
- }
13
- const thumbnailIconClass = cssClass(cssThumbnailPrefix(ELEMENT_ICON));
14
- if (!isImageSlide(slide)) {
15
- if (slide.type === "video") {
16
- return (React.createElement(React.Fragment, null,
17
- "poster" in slide && (React.createElement("img", { alt: "", src: slide.poster, className: clsx(cssClass(CLASS_FULLSIZE), cssClass(cssPrefix("contain_image"))) })),
18
- React.createElement(VideoThumbnailIcon, { className: thumbnailIconClass })));
19
- }
20
- }
21
- else {
22
- return React.createElement(ImageSlide, { slide: slide, render: render, rect: rect, imageFit: imageFit });
23
- }
24
- return React.createElement(UnknownThumbnailIcon, { className: thumbnailIconClass });
25
- }
26
- const activePrefix = makeComposePrefix("active");
27
- const fadeInPrefix = makeComposePrefix("fadein");
28
- const fadeOutPrefix = makeComposePrefix("fadeout");
29
- const placeholderPrefix = makeComposePrefix("placeholder");
30
- const DELAY = "delay";
31
- const DURATION = "duration";
32
- export function Thumbnail({ slide, onClick, active, fadeIn, fadeOut, placeholder }) {
33
- const { render, styles } = useLightboxProps();
34
- const { width, height, imageFit } = useThumbnailsProps();
35
- const rect = { width, height };
36
- return (React.createElement("button", { type: "button", className: clsx(cssClass(CLASS_FLEX_CENTER), cssClass(cssThumbnailPrefix()), active && cssClass(cssThumbnailPrefix(activePrefix())), fadeIn && cssClass(cssThumbnailPrefix(fadeInPrefix())), fadeOut && cssClass(cssThumbnailPrefix(fadeOutPrefix())), placeholder && cssClass(cssThumbnailPrefix(placeholderPrefix()))), style: {
37
- ...(fadeIn
38
- ? {
39
- [cssVar(cssThumbnailPrefix(fadeInPrefix(DURATION)))]: `${fadeIn.duration}ms`,
40
- [cssVar(cssThumbnailPrefix(fadeInPrefix(DELAY)))]: `${fadeIn.delay}ms`,
41
- }
42
- : null),
43
- ...(fadeOut
44
- ? {
45
- [cssVar(cssThumbnailPrefix(fadeOutPrefix(DURATION)))]: `${fadeOut.duration}ms`,
46
- [cssVar(cssThumbnailPrefix(fadeOutPrefix(DELAY)))]: `${fadeOut.delay}ms`,
47
- }
48
- : null),
49
- ...styles.thumbnail,
50
- }, onClick: onClick }, slide && renderThumbnail({ slide, render, rect, imageFit })));
51
- }
@@ -1,3 +0,0 @@
1
- import { PluginProps } from "../../types.js";
2
- /** Thumbnails plugin */
3
- export declare function Thumbnails({ augment, contains, append, addParent }: PluginProps): void;
@@ -1,22 +0,0 @@
1
- import * as React from "react";
2
- import { addToolbarButton, createModule, MODULE_CONTROLLER, PLUGIN_FULLSCREEN, PLUGIN_THUMBNAILS, } from "../../core/index.js";
3
- import { resolveThumbnailsProps } from "./props.js";
4
- import { ThumbnailsContextProvider } from "./ThumbnailsContext.js";
5
- import { ThumbnailsButton } from "./ThumbnailsButton.js";
6
- export function Thumbnails({ augment, contains, append, addParent }) {
7
- augment(({ thumbnails: thumbnailsProps, toolbar, ...restProps }) => {
8
- const thumbnails = resolveThumbnailsProps(thumbnailsProps);
9
- return {
10
- toolbar: addToolbarButton(toolbar, PLUGIN_THUMBNAILS, thumbnails.showToggle ? React.createElement(ThumbnailsButton, null) : null),
11
- thumbnails,
12
- ...restProps,
13
- };
14
- });
15
- const module = createModule(PLUGIN_THUMBNAILS, ThumbnailsContextProvider);
16
- if (contains(PLUGIN_FULLSCREEN)) {
17
- append(PLUGIN_FULLSCREEN, module);
18
- }
19
- else {
20
- addParent(MODULE_CONTROLLER, module);
21
- }
22
- }
@@ -1,2 +0,0 @@
1
- import * as React from "react";
2
- export declare function ThumbnailsButton(): React.JSX.Element;
@@ -1,16 +0,0 @@
1
- import * as React from "react";
2
- import { createIcon, createIconDisabled, IconButton, useLightboxProps } from "../../core/index.js";
3
- import { useThumbnails } from "./ThumbnailsContext.js";
4
- const thumbnailsIcon = () => (React.createElement(React.Fragment, null,
5
- React.createElement("path", { strokeWidth: 2, stroke: "currentColor", strokeLinejoin: "round", fill: "none", d: "M3 5l18 0l0 14l-18 0l0-14z" }),
6
- React.createElement("path", { d: "M5 14h4v3h-4zM10 14h4v3h-4zM15 14h4v3h-4z" })));
7
- const ThumbnailsVisible = createIcon("ThumbnailsVisible", thumbnailsIcon());
8
- const ThumbnailsHidden = createIconDisabled("ThumbnailsHidden", thumbnailsIcon());
9
- export function ThumbnailsButton() {
10
- const { visible, show, hide } = useThumbnails();
11
- const { render } = useLightboxProps();
12
- if (render.buttonThumbnails) {
13
- return React.createElement(React.Fragment, null, render.buttonThumbnails({ visible, show, hide }));
14
- }
15
- return (React.createElement(IconButton, { label: visible ? "Hide thumbnails" : "Show thumbnails", icon: visible ? ThumbnailsVisible : ThumbnailsHidden, renderIcon: visible ? render.iconThumbnailsVisible : render.iconThumbnailsHidden, onClick: visible ? hide : show }));
16
- }
@@ -1,6 +0,0 @@
1
- import * as React from "react";
2
- import { ComponentProps, ThumbnailsRef } from "../../types.js";
3
- export declare const ThumbnailsContext: React.Context<ThumbnailsRef | null>;
4
- export declare const useThumbnails: () => ThumbnailsRef;
5
- /** Thumbnails plugin component */
6
- export declare function ThumbnailsContextProvider({ children, ...props }: ComponentProps): React.JSX.Element;
@@ -1,24 +0,0 @@
1
- import * as React from "react";
2
- import { clsx, cssClass, LightboxPropsProvider, makeUseContext } from "../../core/index.js";
3
- import { cssPrefix } from "./utils.js";
4
- import { ThumbnailsTrack } from "./ThumbnailsTrack.js";
5
- import { resolveThumbnailsProps } from "./props.js";
6
- export const ThumbnailsContext = React.createContext(null);
7
- export const useThumbnails = makeUseContext("useThumbnails", "ThumbnailsContext", ThumbnailsContext);
8
- export function ThumbnailsContextProvider({ children, ...props }) {
9
- const [visible, setVisible] = React.useState(true);
10
- const containerRef = React.useRef(null);
11
- const { ref, position } = resolveThumbnailsProps(props.thumbnails);
12
- const context = React.useMemo(() => ({
13
- visible,
14
- show: () => setVisible(true),
15
- hide: () => setVisible(false),
16
- }), [visible]);
17
- React.useImperativeHandle(ref, () => context, [context]);
18
- return (React.createElement(LightboxPropsProvider, { ...props },
19
- React.createElement(ThumbnailsContext.Provider, { value: context },
20
- React.createElement("div", { ref: containerRef, className: clsx(cssClass(cssPrefix()), cssClass(cssPrefix(`${position}`))) },
21
- ["start", "top"].includes(position) && React.createElement(ThumbnailsTrack, { containerRef: containerRef }),
22
- React.createElement("div", { className: cssClass(cssPrefix("wrapper")) }, children),
23
- ["end", "bottom"].includes(position) && React.createElement(ThumbnailsTrack, { containerRef: containerRef })))));
24
- }
@@ -1,5 +0,0 @@
1
- import * as React from "react";
2
- export type ThumbnailsTrackProps = {
3
- containerRef: React.RefObject<HTMLDivElement>;
4
- };
5
- export declare function ThumbnailsTrack({ containerRef }: ThumbnailsTrackProps): React.JSX.Element;
@@ -1,141 +0,0 @@
1
- import * as React from "react";
2
- import { ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, CLASS_FLEX_CENTER, cleanup, clsx, cssClass, cssVar, getSlide, hasSlides, useAnimation, useEventCallback, useEvents, useLightboxProps, useLightboxState, useRTL, } from "../../core/index.js";
3
- import { cssPrefix, cssThumbnailPrefix } from "./utils.js";
4
- import { Thumbnail } from "./Thumbnail.js";
5
- import { defaultThumbnailsProps, useThumbnailsProps } from "./props.js";
6
- import { useThumbnails } from "./ThumbnailsContext.js";
7
- function isHorizontal(position) {
8
- return ["top", "bottom"].includes(position);
9
- }
10
- function boxSize(thumbnails, dimension, includeGap) {
11
- return dimension + 2 * (thumbnails.border + thumbnails.padding) + (includeGap ? thumbnails.gap : 0);
12
- }
13
- export function ThumbnailsTrack({ containerRef }) {
14
- const track = React.useRef(null);
15
- const { visible } = useThumbnails();
16
- const { carousel, styles } = useLightboxProps();
17
- const { slides, globalIndex, animation } = useLightboxState();
18
- const { publish, subscribe } = useEvents();
19
- const isRTL = useRTL();
20
- const thumbnails = useThumbnailsProps();
21
- const { position, width, height, border, borderRadius, padding, gap, vignette } = thumbnails;
22
- const index = globalIndex;
23
- const animationDuration = (animation === null || animation === void 0 ? void 0 : animation.duration) || 0;
24
- const offset = (animationDuration > 0 && (animation === null || animation === void 0 ? void 0 : animation.increment)) || 0;
25
- const { prepareAnimation } = useAnimation(track, (snapshot) => ({
26
- keyframes: isHorizontal(position)
27
- ? [
28
- {
29
- transform: `translateX(${(isRTL ? -1 : 1) * boxSize(thumbnails, width, true) * offset + snapshot}px)`,
30
- },
31
- { transform: "translateX(0)" },
32
- ]
33
- : [
34
- {
35
- transform: `translateY(${boxSize(thumbnails, height, true) * offset + snapshot}px)`,
36
- },
37
- { transform: "translateY(0)" },
38
- ],
39
- duration: animationDuration,
40
- easing: animation === null || animation === void 0 ? void 0 : animation.easing,
41
- }));
42
- const handleControllerSwipe = useEventCallback(() => {
43
- let animationOffset;
44
- if (containerRef.current && track.current) {
45
- const containerRect = containerRef.current.getBoundingClientRect();
46
- const trackRect = track.current.getBoundingClientRect();
47
- animationOffset = isHorizontal(position)
48
- ? trackRect.left - containerRect.left - (containerRect.width - trackRect.width) / 2
49
- : trackRect.top - containerRect.top - (containerRect.height - trackRect.height) / 2;
50
- }
51
- else {
52
- animationOffset = 0;
53
- }
54
- prepareAnimation(animationOffset);
55
- });
56
- React.useEffect(() => cleanup(subscribe(ACTION_SWIPE, handleControllerSwipe)), [subscribe, handleControllerSwipe]);
57
- const { finite } = carousel;
58
- const preload = Math.max(Math.min(carousel.preload, slides.length - 1), 0);
59
- const items = [];
60
- if (hasSlides(slides)) {
61
- if (offset < 0) {
62
- for (let i = index - preload + offset; i < index - preload; i += 1) {
63
- items.push({ slide: null, index: i, placeholder: true });
64
- }
65
- }
66
- for (let i = index - preload - (offset > 0 ? offset : 0); i < index; i += 1) {
67
- if (!(finite && i < 0)) {
68
- items.push({ slide: getSlide(slides, i), index: i });
69
- }
70
- else {
71
- items.push({ slide: null, index: i, placeholder: true });
72
- }
73
- }
74
- items.push({ slide: getSlide(slides, index), index });
75
- for (let i = index + 1; i <= index + preload - (offset < 0 ? offset : 0); i += 1) {
76
- if (!finite || i <= slides.length - 1) {
77
- items.push({ slide: getSlide(slides, i), index: i });
78
- }
79
- else {
80
- items.push({ slide: null, index: i, placeholder: true });
81
- }
82
- }
83
- if (offset > 0) {
84
- for (let i = index + preload + 1; i <= index + preload + offset; i += 1) {
85
- items.push({ slide: null, index: i, placeholder: true });
86
- }
87
- }
88
- }
89
- const handleClick = (slideIndex) => () => {
90
- if (slideIndex > index) {
91
- publish(ACTION_NEXT, { count: slideIndex - index });
92
- }
93
- else if (slideIndex < index) {
94
- publish(ACTION_PREV, { count: index - slideIndex });
95
- }
96
- };
97
- return (React.createElement("div", { className: clsx(cssClass(cssPrefix("container")), cssClass(CLASS_FLEX_CENTER)), style: {
98
- ...(!visible ? { display: "none" } : null),
99
- ...(width !== defaultThumbnailsProps.width
100
- ? { [cssVar(cssThumbnailPrefix("width"))]: `${boxSize(thumbnails, width)}px` }
101
- : null),
102
- ...(height !== defaultThumbnailsProps.height
103
- ? { [cssVar(cssThumbnailPrefix("height"))]: `${boxSize(thumbnails, height)}px` }
104
- : null),
105
- ...(border !== defaultThumbnailsProps.border
106
- ? { [cssVar(cssThumbnailPrefix("border"))]: `${border}px` }
107
- : null),
108
- ...(borderRadius !== defaultThumbnailsProps.borderRadius
109
- ? { [cssVar(cssThumbnailPrefix("border_radius"))]: `${borderRadius}px` }
110
- : null),
111
- ...(padding !== defaultThumbnailsProps.padding
112
- ? { [cssVar(cssThumbnailPrefix("padding"))]: `${padding}px` }
113
- : null),
114
- ...(gap !== defaultThumbnailsProps.gap ? { [cssVar(cssThumbnailPrefix("gap"))]: `${gap}px` } : null),
115
- ...styles.thumbnailsContainer,
116
- } },
117
- React.createElement("nav", { ref: track, style: styles.thumbnailsTrack, className: clsx(cssClass(cssPrefix("track")), cssClass(CLASS_FLEX_CENTER)) }, items.map(({ slide, index: slideIndex, placeholder }) => {
118
- const fadeAnimationDuration = animationDuration / Math.abs(offset || 1);
119
- const fadeIn = (offset > 0 && slideIndex > index + preload - offset && slideIndex <= index + preload) ||
120
- (offset < 0 && slideIndex < index - preload - offset && slideIndex >= index - preload)
121
- ? {
122
- duration: fadeAnimationDuration,
123
- delay: ((offset > 0
124
- ? slideIndex - (index + preload - offset)
125
- : index - preload - offset - slideIndex) -
126
- 1) *
127
- fadeAnimationDuration,
128
- }
129
- : undefined;
130
- const fadeOut = (offset > 0 && slideIndex < index - preload) || (offset < 0 && slideIndex > index + preload)
131
- ? {
132
- duration: fadeAnimationDuration,
133
- delay: (offset > 0
134
- ? offset - (index - preload - slideIndex)
135
- : -offset - (slideIndex - (index + preload))) * fadeAnimationDuration,
136
- }
137
- : undefined;
138
- return (React.createElement(Thumbnail, { key: slideIndex, slide: slide, active: slideIndex === index, fadeIn: fadeIn, fadeOut: fadeOut, placeholder: Boolean(placeholder), onClick: handleClick(slideIndex) }));
139
- })),
140
- vignette && React.createElement("div", { className: cssClass(cssPrefix("vignette")) })));
141
- }
@@ -1,40 +0,0 @@
1
- /// <reference types="react" />
2
- import { LightboxProps } from "../../types.js";
3
- export declare const defaultThumbnailsProps: {
4
- ref: null;
5
- position: "bottom";
6
- width: number;
7
- height: number;
8
- border: number;
9
- borderRadius: number;
10
- padding: number;
11
- gap: number;
12
- imageFit: "contain";
13
- vignette: boolean;
14
- };
15
- export declare const resolveThumbnailsProps: (thumbnails: LightboxProps["thumbnails"]) => {
16
- ref: import("react").ForwardedRef<import("../../types.js").ThumbnailsRef>;
17
- position: "end" | "start" | "bottom" | "top";
18
- width: number;
19
- height: number;
20
- border: number;
21
- borderRadius: number;
22
- padding: number;
23
- gap: number;
24
- imageFit: import("../../types.js").ImageFit;
25
- vignette: boolean;
26
- showToggle?: boolean | undefined;
27
- };
28
- export declare function useThumbnailsProps(): {
29
- ref: import("react").ForwardedRef<import("../../types.js").ThumbnailsRef>;
30
- position: "end" | "start" | "bottom" | "top";
31
- width: number;
32
- height: number;
33
- border: number;
34
- borderRadius: number;
35
- padding: number;
36
- gap: number;
37
- imageFit: import("../../types.js").ImageFit;
38
- vignette: boolean;
39
- showToggle?: boolean | undefined;
40
- };