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,49 +0,0 @@
1
- import * as React from "react";
2
- import { getSlideIfPresent, getSlideIndex, makeUseContext } from "../utils.js";
3
- import { UNKNOWN_ACTION_TYPE } from "../consts.js";
4
- export const LightboxStateContext = React.createContext(null);
5
- export const useLightboxState = makeUseContext("useLightboxState", "LightboxStateContext", LightboxStateContext);
6
- export const LightboxDispatchContext = React.createContext(null);
7
- export const useLightboxDispatch = makeUseContext("useLightboxDispatch", "LightboxDispatchContext", LightboxDispatchContext);
8
- function reducer(state, action) {
9
- switch (action.type) {
10
- case "swipe": {
11
- const { slides } = state;
12
- const increment = (action === null || action === void 0 ? void 0 : action.increment) || 0;
13
- const globalIndex = state.globalIndex + increment;
14
- const currentIndex = getSlideIndex(globalIndex, slides.length);
15
- const currentSlide = getSlideIfPresent(slides, currentIndex);
16
- const animation = increment || action.duration
17
- ? {
18
- increment,
19
- duration: action.duration,
20
- easing: action.easing,
21
- }
22
- : undefined;
23
- return { slides, currentIndex, globalIndex, currentSlide, animation };
24
- }
25
- case "update":
26
- return {
27
- slides: action.slides,
28
- currentIndex: action.index,
29
- globalIndex: action.index,
30
- currentSlide: getSlideIfPresent(action.slides, action.index),
31
- };
32
- default:
33
- throw new Error(UNKNOWN_ACTION_TYPE);
34
- }
35
- }
36
- export function LightboxStateProvider({ slides, index, children }) {
37
- const [state, dispatch] = React.useReducer(reducer, {
38
- slides,
39
- currentIndex: index,
40
- globalIndex: index,
41
- currentSlide: getSlideIfPresent(slides, index),
42
- });
43
- React.useEffect(() => {
44
- dispatch({ type: "update", slides, index });
45
- }, [slides, index]);
46
- const context = React.useMemo(() => ({ ...state, state, dispatch }), [state, dispatch]);
47
- return (React.createElement(LightboxDispatchContext.Provider, { value: dispatch },
48
- React.createElement(LightboxStateContext.Provider, { value: context }, children)));
49
- }
@@ -1,8 +0,0 @@
1
- import * as React from "react";
2
- export type TimeoutsContextType = {
3
- setTimeout: (fn: () => void, delay?: number) => number;
4
- clearTimeout: (id?: number) => void;
5
- };
6
- export declare const TimeoutsContext: React.Context<TimeoutsContextType | null>;
7
- export declare const useTimeouts: () => TimeoutsContextType;
8
- export declare function TimeoutsProvider({ children }: React.PropsWithChildren): React.JSX.Element;
@@ -1,32 +0,0 @@
1
- import * as React from "react";
2
- import { makeUseContext } from "../utils.js";
3
- export const TimeoutsContext = React.createContext(null);
4
- export const useTimeouts = makeUseContext("useTimeouts", "TimeoutsContext", TimeoutsContext);
5
- export function TimeoutsProvider({ children }) {
6
- const [timeouts] = React.useState([]);
7
- React.useEffect(() => () => {
8
- timeouts.forEach((tid) => window.clearTimeout(tid));
9
- timeouts.splice(0, timeouts.length);
10
- }, [timeouts]);
11
- const context = React.useMemo(() => {
12
- const removeTimeout = (id) => {
13
- timeouts.splice(0, timeouts.length, ...timeouts.filter((tid) => tid !== id));
14
- };
15
- const setTimeout = (fn, delay) => {
16
- const id = window.setTimeout(() => {
17
- removeTimeout(id);
18
- fn();
19
- }, delay);
20
- timeouts.push(id);
21
- return id;
22
- };
23
- const clearTimeout = (id) => {
24
- if (id !== undefined) {
25
- removeTimeout(id);
26
- window.clearTimeout(id);
27
- }
28
- };
29
- return { setTimeout, clearTimeout };
30
- }, [timeouts]);
31
- return React.createElement(TimeoutsContext.Provider, { value: context }, children);
32
- }
@@ -1,4 +0,0 @@
1
- export * from "./Events.js";
2
- export * from "./LightboxProps.js";
3
- export * from "./LightboxState.js";
4
- export * from "./Timeouts.js";
@@ -1,4 +0,0 @@
1
- export * from "./Events.js";
2
- export * from "./LightboxProps.js";
3
- export * from "./LightboxState.js";
4
- export * from "./Timeouts.js";
@@ -1,11 +0,0 @@
1
- export * from "./useAnimation.js";
2
- export * from "./useContainerRect.js";
3
- export * from "./useDelay.js";
4
- export * from "./useEventCallback.js";
5
- export * from "./useForkRef.js";
6
- export * from "./useLayoutEffect.js";
7
- export * from "./useLoseFocus.js";
8
- export * from "./useMotionPreference.js";
9
- export * from "./useRTL.js";
10
- export * from "./useSensors.js";
11
- export * from "./useThrottle.js";
@@ -1,11 +0,0 @@
1
- export * from "./useAnimation.js";
2
- export * from "./useContainerRect.js";
3
- export * from "./useDelay.js";
4
- export * from "./useEventCallback.js";
5
- export * from "./useForkRef.js";
6
- export * from "./useLayoutEffect.js";
7
- export * from "./useLoseFocus.js";
8
- export * from "./useMotionPreference.js";
9
- export * from "./useRTL.js";
10
- export * from "./useSensors.js";
11
- export * from "./useThrottle.js";
@@ -1,15 +0,0 @@
1
- import * as React from "react";
2
- export type ComputeAnimation<T> = (snapshot: T, rect: DOMRect, translate: {
3
- x: number;
4
- y: number;
5
- z: number;
6
- }) => {
7
- keyframes: Keyframe[];
8
- duration: number;
9
- easing?: string;
10
- onfinish?: () => void;
11
- } | undefined;
12
- export declare function useAnimation<T>(nodeRef: React.RefObject<HTMLElement | null>, computeAnimation: ComputeAnimation<T>): {
13
- prepareAnimation: (currentSnapshot: T | undefined) => void;
14
- isAnimationPlaying: () => boolean;
15
- };
@@ -1,57 +0,0 @@
1
- import * as React from "react";
2
- import { useLayoutEffect } from "./useLayoutEffect.js";
3
- import { useMotionPreference } from "./useMotionPreference.js";
4
- function currentTransformation(node) {
5
- let x = 0;
6
- let y = 0;
7
- let z = 0;
8
- const matrix = window.getComputedStyle(node).transform;
9
- const matcher = matrix.match(/matrix.*\((.+)\)/);
10
- if (matcher) {
11
- const values = matcher[1].split(",").map((str) => Number.parseInt(str, 10));
12
- if (values.length === 6) {
13
- x = values[4];
14
- y = values[5];
15
- }
16
- else if (values.length === 16) {
17
- x = values[12];
18
- y = values[13];
19
- z = values[14];
20
- }
21
- }
22
- return { x, y, z };
23
- }
24
- export function useAnimation(nodeRef, computeAnimation) {
25
- const snapshot = React.useRef();
26
- const animation = React.useRef();
27
- const reduceMotion = useMotionPreference();
28
- useLayoutEffect(() => {
29
- var _a, _b, _c;
30
- if (nodeRef.current && snapshot.current !== undefined && !reduceMotion) {
31
- const { keyframes, duration, easing, onfinish } = computeAnimation(snapshot.current, nodeRef.current.getBoundingClientRect(), currentTransformation(nodeRef.current)) || {};
32
- if (keyframes && duration) {
33
- (_a = animation.current) === null || _a === void 0 ? void 0 : _a.cancel();
34
- animation.current = undefined;
35
- try {
36
- animation.current = (_c = (_b = nodeRef.current).animate) === null || _c === void 0 ? void 0 : _c.call(_b, keyframes, { duration, easing });
37
- }
38
- catch (err) {
39
- console.error(err);
40
- }
41
- if (animation.current) {
42
- animation.current.onfinish = () => {
43
- animation.current = undefined;
44
- onfinish === null || onfinish === void 0 ? void 0 : onfinish();
45
- };
46
- }
47
- }
48
- }
49
- snapshot.current = undefined;
50
- });
51
- return {
52
- prepareAnimation: (currentSnapshot) => {
53
- snapshot.current = currentSnapshot;
54
- },
55
- isAnimationPlaying: () => { var _a; return ((_a = animation.current) === null || _a === void 0 ? void 0 : _a.playState) === "running"; },
56
- };
57
- }
@@ -1,7 +0,0 @@
1
- import * as React from "react";
2
- import { ContainerRect } from "../../types.js";
3
- export declare function useContainerRect<T extends HTMLElement = HTMLElement>(): {
4
- setContainerRef: (node: T | null) => void;
5
- containerRef: React.MutableRefObject<T | null>;
6
- containerRect: ContainerRect | undefined;
7
- };
@@ -1,36 +0,0 @@
1
- import * as React from "react";
2
- export function useContainerRect() {
3
- const [containerRect, setContainerRect] = React.useState();
4
- const containerRef = React.useRef(null);
5
- const observerRef = React.useRef();
6
- const setContainerRef = React.useCallback((node) => {
7
- containerRef.current = node;
8
- if (observerRef.current) {
9
- observerRef.current.disconnect();
10
- observerRef.current = undefined;
11
- }
12
- const updateContainerRect = () => {
13
- if (node) {
14
- const styles = window.getComputedStyle(node);
15
- const parse = (value) => parseFloat(value) || 0;
16
- setContainerRect({
17
- width: Math.round(node.clientWidth - parse(styles.paddingLeft) - parse(styles.paddingRight)),
18
- height: Math.round(node.clientHeight - parse(styles.paddingTop) - parse(styles.paddingBottom)),
19
- });
20
- }
21
- else {
22
- setContainerRect(undefined);
23
- }
24
- };
25
- updateContainerRect();
26
- if (node && typeof ResizeObserver !== "undefined") {
27
- observerRef.current = new ResizeObserver(updateContainerRect);
28
- observerRef.current.observe(node);
29
- }
30
- }, []);
31
- return React.useMemo(() => ({
32
- setContainerRef,
33
- containerRef,
34
- containerRect,
35
- }), [setContainerRef, containerRef, containerRect]);
36
- }
@@ -1 +0,0 @@
1
- export declare function useDelay(): (callback: () => void, delay: number) => void;
@@ -1,10 +0,0 @@
1
- import * as React from "react";
2
- import { useTimeouts } from "../contexts/Timeouts.js";
3
- export function useDelay() {
4
- const timeoutId = React.useRef();
5
- const { setTimeout, clearTimeout } = useTimeouts();
6
- return React.useCallback((callback, delay) => {
7
- clearTimeout(timeoutId.current);
8
- timeoutId.current = setTimeout(callback, delay > 0 ? delay : 0);
9
- }, [setTimeout, clearTimeout]);
10
- }
@@ -1 +0,0 @@
1
- export declare function useEventCallback<Args extends unknown[], Return>(fn: (...args: Args) => Return): (...args: Args) => Return;
@@ -1,9 +0,0 @@
1
- import * as React from "react";
2
- import { useLayoutEffect } from "./useLayoutEffect.js";
3
- export function useEventCallback(fn) {
4
- const ref = React.useRef(fn);
5
- useLayoutEffect(() => {
6
- ref.current = fn;
7
- });
8
- return React.useCallback((...args) => { var _a; return (_a = ref.current) === null || _a === void 0 ? void 0 : _a.call(ref, ...args); }, []);
9
- }
@@ -1,3 +0,0 @@
1
- import * as React from "react";
2
- export declare function setRef<T>(ref: React.MutableRefObject<T | null> | ((instance: T | null) => void) | null | undefined, value: T | null): void;
3
- export declare function useForkRef<InstanceA, InstanceB>(refA: React.Ref<InstanceA> | null | undefined, refB: React.Ref<InstanceB> | null | undefined): React.Ref<InstanceA & InstanceB> | null;
@@ -1,17 +0,0 @@
1
- import * as React from "react";
2
- export function setRef(ref, value) {
3
- if (typeof ref === "function") {
4
- ref(value);
5
- }
6
- else if (ref) {
7
- ref.current = value;
8
- }
9
- }
10
- export function useForkRef(refA, refB) {
11
- return React.useMemo(() => refA == null && refB == null
12
- ? null
13
- : (refValue) => {
14
- setRef(refA, refValue);
15
- setRef(refB, refValue);
16
- }, [refA, refB]);
17
- }
@@ -1,2 +0,0 @@
1
- import * as React from "react";
2
- export declare const useLayoutEffect: typeof React.useLayoutEffect;
@@ -1,3 +0,0 @@
1
- import * as React from "react";
2
- import { hasWindow } from "../utils.js";
3
- export const useLayoutEffect = hasWindow() ? React.useLayoutEffect : React.useEffect;
@@ -1,4 +0,0 @@
1
- export declare function useLoseFocus(disabled?: boolean): {
2
- onFocus: () => void;
3
- onBlur: () => void;
4
- };
@@ -1,19 +0,0 @@
1
- import * as React from "react";
2
- import { useLayoutEffect } from "./useLayoutEffect.js";
3
- import { useController } from "../modules/Controller.js";
4
- export function useLoseFocus(disabled = false) {
5
- const focused = React.useRef(disabled);
6
- const { focus } = useController();
7
- useLayoutEffect(() => {
8
- if (disabled) {
9
- focus();
10
- }
11
- }, [disabled, focus]);
12
- const onFocus = React.useCallback(() => {
13
- focused.current = true;
14
- }, []);
15
- const onBlur = React.useCallback(() => {
16
- focused.current = false;
17
- }, []);
18
- return { onFocus, onBlur };
19
- }
@@ -1 +0,0 @@
1
- export declare function useMotionPreference(): boolean;
@@ -1,13 +0,0 @@
1
- import * as React from "react";
2
- export function useMotionPreference() {
3
- const [reduceMotion, setReduceMotion] = React.useState(false);
4
- React.useEffect(() => {
5
- var _a, _b;
6
- const mediaQuery = (_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, "(prefers-reduced-motion: reduce)");
7
- setReduceMotion(mediaQuery === null || mediaQuery === void 0 ? void 0 : mediaQuery.matches);
8
- const listener = (event) => setReduceMotion(event.matches);
9
- (_b = mediaQuery === null || mediaQuery === void 0 ? void 0 : mediaQuery.addEventListener) === null || _b === void 0 ? void 0 : _b.call(mediaQuery, "change", listener);
10
- return () => { var _a; return (_a = mediaQuery === null || mediaQuery === void 0 ? void 0 : mediaQuery.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(mediaQuery, "change", listener); };
11
- }, []);
12
- return reduceMotion;
13
- }
@@ -1 +0,0 @@
1
- export declare function useRTL(): boolean;
@@ -1,9 +0,0 @@
1
- import * as React from "react";
2
- import { useLayoutEffect } from "./useLayoutEffect.js";
3
- export function useRTL() {
4
- const [isRTL, setIsRTL] = React.useState(false);
5
- useLayoutEffect(() => {
6
- setIsRTL(window.getComputedStyle(window.document.documentElement).direction === "rtl");
7
- }, []);
8
- return isRTL;
9
- }
@@ -1,14 +0,0 @@
1
- import * as React from "react";
2
- export type PointerEventType = "onPointerDown" | "onPointerMove" | "onPointerUp" | "onPointerLeave" | "onPointerCancel";
3
- export type KeyboardEventType = "onKeyDown" | "onKeyUp";
4
- export type WheelEventType = "onWheel";
5
- export type SupportedEventType = PointerEventType | KeyboardEventType | WheelEventType;
6
- export type ReactEventType<T, K> = K extends KeyboardEventType ? React.KeyboardEvent<T> : K extends WheelEventType ? React.WheelEvent<T> : K extends PointerEventType ? React.PointerEvent<T> : never;
7
- export type EventCallback<T, P extends React.PointerEvent<T> | React.KeyboardEvent<T> | React.WheelEvent<T>> = (event: P) => void;
8
- export type SubscribeSensors<T> = <ET extends SupportedEventType>(type: ET, callback: EventCallback<T, ReactEventType<T, ET>>) => () => void;
9
- export type RegisterSensors<T> = Required<Pick<React.HTMLAttributes<T>, PointerEventType>> & Required<Pick<React.HTMLAttributes<T>, KeyboardEventType>> & Required<Pick<React.HTMLAttributes<T>, WheelEventType>>;
10
- export type UseSensors<T> = {
11
- registerSensors: RegisterSensors<T>;
12
- subscribeSensors: SubscribeSensors<T>;
13
- };
14
- export declare function useSensors<T extends Element>(): UseSensors<T>;
@@ -1,38 +0,0 @@
1
- import * as React from "react";
2
- import { EVENT_ON_KEY_DOWN, EVENT_ON_KEY_UP, EVENT_ON_POINTER_CANCEL, EVENT_ON_POINTER_DOWN, EVENT_ON_POINTER_LEAVE, EVENT_ON_POINTER_MOVE, EVENT_ON_POINTER_UP, EVENT_ON_WHEEL, } from "../consts.js";
3
- export function useSensors() {
4
- const [subscribers] = React.useState({});
5
- return React.useMemo(() => {
6
- const notifySubscribers = (type, event) => {
7
- var _a;
8
- (_a = subscribers[type]) === null || _a === void 0 ? void 0 : _a.forEach((listener) => {
9
- if (!event.isPropagationStopped())
10
- listener(event);
11
- });
12
- };
13
- return {
14
- registerSensors: {
15
- onPointerDown: (event) => notifySubscribers(EVENT_ON_POINTER_DOWN, event),
16
- onPointerMove: (event) => notifySubscribers(EVENT_ON_POINTER_MOVE, event),
17
- onPointerUp: (event) => notifySubscribers(EVENT_ON_POINTER_UP, event),
18
- onPointerLeave: (event) => notifySubscribers(EVENT_ON_POINTER_LEAVE, event),
19
- onPointerCancel: (event) => notifySubscribers(EVENT_ON_POINTER_CANCEL, event),
20
- onKeyDown: (event) => notifySubscribers(EVENT_ON_KEY_DOWN, event),
21
- onKeyUp: (event) => notifySubscribers(EVENT_ON_KEY_UP, event),
22
- onWheel: (event) => notifySubscribers(EVENT_ON_WHEEL, event),
23
- },
24
- subscribeSensors: (type, callback) => {
25
- if (!subscribers[type]) {
26
- subscribers[type] = [];
27
- }
28
- subscribers[type].unshift(callback);
29
- return () => {
30
- const listeners = subscribers[type];
31
- if (listeners) {
32
- listeners.splice(0, listeners.length, ...listeners.filter((el) => el !== callback));
33
- }
34
- };
35
- },
36
- };
37
- }, [subscribers]);
38
- }
@@ -1 +0,0 @@
1
- export declare function useThrottle(callback: (...args: any[]) => void, delay: number): (...args: any[]) => void;
@@ -1,16 +0,0 @@
1
- import * as React from "react";
2
- import { useDelay } from "./useDelay.js";
3
- import { useEventCallback } from "./useEventCallback.js";
4
- export function useThrottle(callback, delay) {
5
- const lastCallbackTime = React.useRef(0);
6
- const delayCallback = useDelay();
7
- const executeCallback = useEventCallback((...args) => {
8
- lastCallbackTime.current = Date.now();
9
- callback(args);
10
- });
11
- return React.useCallback((...args) => {
12
- delayCallback(() => {
13
- executeCallback(args);
14
- }, delay - (Date.now() - lastCallbackTime.current));
15
- }, [delay, executeCallback, delayCallback]);
16
- }
@@ -1,7 +0,0 @@
1
- export * from "./consts.js";
2
- export * from "./utils.js";
3
- export * from "./config.js";
4
- export * from "./hooks/index.js";
5
- export * from "./contexts/index.js";
6
- export * from "./components/index.js";
7
- export * from "./modules/index.js";
@@ -1,7 +0,0 @@
1
- export * from "./consts.js";
2
- export * from "./utils.js";
3
- export * from "./config.js";
4
- export * from "./hooks/index.js";
5
- export * from "./contexts/index.js";
6
- export * from "./components/index.js";
7
- export * from "./modules/index.js";
@@ -1,4 +0,0 @@
1
- import * as React from "react";
2
- import { ComponentProps } from "../../types.js";
3
- export declare function Carousel({ carousel: { finite, preload, padding, spacing } }: ComponentProps): React.JSX.Element;
4
- export declare const CarouselModule: import("../../types.js").Module;
@@ -1,72 +0,0 @@
1
- import * as React from "react";
2
- import { createModule } from "../config.js";
3
- import { clsx, composePrefix, cssClass, cssVar, isImageSlide, parseLengthPercentage } from "../utils.js";
4
- import { ImageSlide } from "../components/index.js";
5
- import { useController } from "./Controller.js";
6
- import { useLightboxProps, useLightboxState } from "../contexts/index.js";
7
- import { CLASS_FLEX_CENTER, CLASS_FULLSIZE, MODULE_CAROUSEL } from "../consts.js";
8
- function cssPrefix(value) {
9
- return composePrefix(MODULE_CAROUSEL, value);
10
- }
11
- function cssSlidePrefix(value) {
12
- return composePrefix("slide", value);
13
- }
14
- function CarouselSlide({ slide, offset }) {
15
- const containerRef = React.useRef(null);
16
- const { currentIndex } = useLightboxState();
17
- const { slideRect, close } = useController();
18
- const { render, carousel: { imageFit }, on: { click: onClick }, controller: { closeOnBackdropClick }, } = useLightboxProps();
19
- const renderSlide = () => {
20
- var _a, _b, _c, _d;
21
- let rendered = (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, { slide, offset, rect: slideRect });
22
- if (!rendered && isImageSlide(slide)) {
23
- rendered = (React.createElement(ImageSlide, { slide: slide, offset: offset, render: render, rect: slideRect, imageFit: imageFit, onClick: offset === 0 ? () => onClick === null || onClick === void 0 ? void 0 : onClick({ index: currentIndex }) : undefined }));
24
- }
25
- return rendered ? (React.createElement(React.Fragment, null, (_b = render.slideHeader) === null || _b === void 0 ? void 0 :
26
- _b.call(render, { slide }),
27
- ((_c = render.slideContainer) !== null && _c !== void 0 ? _c : (({ children }) => children))({ slide, children: rendered }), (_d = render.slideFooter) === null || _d === void 0 ? void 0 :
28
- _d.call(render, { slide }))) : null;
29
- };
30
- const handleBackdropClick = (event) => {
31
- const container = containerRef.current;
32
- const target = event.target instanceof HTMLElement ? event.target : undefined;
33
- if (closeOnBackdropClick &&
34
- target &&
35
- container &&
36
- (target === container ||
37
- (Array.from(container.children).find((x) => x === target) &&
38
- target.classList.contains(cssClass(CLASS_FULLSIZE))))) {
39
- close();
40
- }
41
- };
42
- return (React.createElement("div", { ref: containerRef, className: clsx(cssClass(cssSlidePrefix()), offset === 0 && cssClass(cssSlidePrefix("current")), cssClass(CLASS_FLEX_CENTER)), onClick: handleBackdropClick }, renderSlide()));
43
- }
44
- function Placeholder() {
45
- return React.createElement("div", { className: cssClass("slide") });
46
- }
47
- export function Carousel({ carousel: { finite, preload, padding, spacing } }) {
48
- const { slides, currentIndex, globalIndex } = useLightboxState();
49
- const { setCarouselRef } = useController();
50
- const spacingValue = parseLengthPercentage(spacing);
51
- const paddingValue = parseLengthPercentage(padding);
52
- const items = [];
53
- if ((slides === null || slides === void 0 ? void 0 : slides.length) > 0) {
54
- for (let i = currentIndex - preload; i < currentIndex; i += 1) {
55
- const key = globalIndex + i - currentIndex;
56
- items.push(!finite || i >= 0 ? (React.createElement(CarouselSlide, { key: key, slide: slides[(i + preload * slides.length) % slides.length], offset: i - currentIndex })) : (React.createElement(Placeholder, { key: key })));
57
- }
58
- items.push(React.createElement(CarouselSlide, { key: globalIndex, slide: slides[currentIndex], offset: 0 }));
59
- for (let i = currentIndex + 1; i <= currentIndex + preload; i += 1) {
60
- const key = globalIndex + i - currentIndex;
61
- items.push(!finite || i <= slides.length - 1 ? (React.createElement(CarouselSlide, { key: key, slide: slides[i % slides.length], offset: i - currentIndex })) : (React.createElement(Placeholder, { key: key })));
62
- }
63
- }
64
- return (React.createElement("div", { ref: setCarouselRef, className: clsx(cssClass(cssPrefix()), items.length > 0 && cssClass(cssPrefix("with_slides"))), style: {
65
- [`${cssVar(cssPrefix("slides_count"))}`]: items.length,
66
- [`${cssVar(cssPrefix("spacing_px"))}`]: spacingValue.pixel || 0,
67
- [`${cssVar(cssPrefix("spacing_percent"))}`]: spacingValue.percent || 0,
68
- [`${cssVar(cssPrefix("padding_px"))}`]: paddingValue.pixel || 0,
69
- [`${cssVar(cssPrefix("padding_percent"))}`]: paddingValue.percent || 0,
70
- } }, items));
71
- }
72
- export const CarouselModule = createModule(MODULE_CAROUSEL, Carousel);
@@ -1,31 +0,0 @@
1
- import * as React from "react";
2
- import { Callback, ComponentProps, ContainerRect, ControllerRef, NavigationAction } from "../../types.js";
3
- import { SubscribeSensors } from "../hooks/index.js";
4
- import { LightboxStateSwipeAction } from "../contexts/index.js";
5
- import { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING } from "../consts.js";
6
- declare module "../index.js" {
7
- interface EventTypes {
8
- [ACTION_PREV]: NavigationAction | void;
9
- [ACTION_NEXT]: NavigationAction | void;
10
- [ACTION_SWIPE]: LightboxStateSwipeAction;
11
- [ACTION_CLOSE]: void;
12
- [ACTIVE_SLIDE_LOADING]: void;
13
- [ACTIVE_SLIDE_PLAYING]: void;
14
- [ACTIVE_SLIDE_COMPLETE]: void;
15
- [ACTIVE_SLIDE_ERROR]: void;
16
- }
17
- }
18
- export type ControllerContextType = Pick<ControllerRef, "prev" | "next" | "close"> & {
19
- focus: Callback;
20
- slideRect: ContainerRect;
21
- containerRect: ContainerRect;
22
- subscribeSensors: SubscribeSensors<HTMLDivElement>;
23
- containerRef: React.RefObject<HTMLDivElement>;
24
- setCarouselRef: React.Ref<HTMLDivElement>;
25
- toolbarWidth: number | undefined;
26
- setToolbarWidth: (width: number | undefined) => void;
27
- };
28
- export declare const ControllerContext: React.Context<ControllerContextType | null>;
29
- export declare const useController: () => NonNullable<ControllerContextType>;
30
- export declare function Controller({ children, ...props }: ComponentProps): React.JSX.Element;
31
- export declare const ControllerModule: import("../../types.js").Module;