yet-another-react-lightbox 2.5.1 → 2.6.1

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 (97) hide show
  1. package/README.md +4 -8
  2. package/dist/Lightbox.d.ts +2 -2
  3. package/dist/Lightbox.js +11 -9
  4. package/dist/core/components/Icons.d.ts +1 -1
  5. package/dist/core/components/Icons.js +2 -2
  6. package/dist/core/components/ImageSlide.d.ts +1 -1
  7. package/dist/core/components/ImageSlide.js +2 -2
  8. package/dist/core/contexts/Events.d.ts +1 -1
  9. package/dist/core/contexts/Events.js +2 -2
  10. package/dist/core/contexts/LightboxState.d.ts +3 -3
  11. package/dist/core/contexts/LightboxState.js +2 -2
  12. package/dist/core/contexts/Timeouts.d.ts +1 -1
  13. package/dist/core/contexts/Timeouts.js +2 -2
  14. package/dist/core/hooks/useAnimation.d.ts +4 -2
  15. package/dist/core/hooks/useAnimation.js +6 -6
  16. package/dist/core/hooks/useContainerRect.d.ts +1 -1
  17. package/dist/core/hooks/useContainerRect.js +2 -2
  18. package/dist/core/hooks/useDelay.d.ts +1 -1
  19. package/dist/core/hooks/useDelay.js +2 -2
  20. package/dist/core/hooks/useEventCallback.d.ts +1 -1
  21. package/dist/core/hooks/useEventCallback.js +2 -2
  22. package/dist/core/hooks/useForkRef.d.ts +2 -2
  23. package/dist/core/hooks/useForkRef.js +10 -8
  24. package/dist/core/hooks/useLoseFocus.d.ts +1 -1
  25. package/dist/core/hooks/useLoseFocus.js +2 -2
  26. package/dist/core/hooks/useMotionPreference.d.ts +1 -1
  27. package/dist/core/hooks/useMotionPreference.js +2 -2
  28. package/dist/core/hooks/useRTL.d.ts +1 -1
  29. package/dist/core/hooks/useRTL.js +2 -2
  30. package/dist/core/hooks/useSensors.d.ts +1 -1
  31. package/dist/core/hooks/useSensors.js +2 -2
  32. package/dist/core/hooks/useThrottle.d.ts +1 -1
  33. package/dist/core/hooks/useThrottle.js +2 -2
  34. package/dist/core/modules/Carousel.d.ts +3 -2
  35. package/dist/core/modules/Carousel.js +25 -15
  36. package/dist/core/modules/Controller.d.ts +2 -2
  37. package/dist/core/modules/Controller.js +13 -11
  38. package/dist/core/modules/Core.d.ts +3 -2
  39. package/dist/core/modules/Core.js +5 -3
  40. package/dist/core/modules/Navigation.d.ts +3 -3
  41. package/dist/core/modules/Navigation.js +7 -5
  42. package/dist/core/modules/NoScroll.d.ts +3 -2
  43. package/dist/core/modules/NoScroll.js +7 -5
  44. package/dist/core/modules/Portal.d.ts +3 -2
  45. package/dist/core/modules/Portal.js +15 -12
  46. package/dist/core/modules/Toolbar.d.ts +3 -2
  47. package/dist/core/modules/Toolbar.js +5 -3
  48. package/dist/core/modules/controller/usePointerSwipe.d.ts +1 -1
  49. package/dist/core/modules/controller/usePointerSwipe.js +2 -2
  50. package/dist/core/modules/controller/usePreventSwipeNavigation.d.ts +1 -1
  51. package/dist/core/modules/controller/usePreventSwipeNavigation.js +4 -4
  52. package/dist/core/modules/controller/useWheelSwipe.d.ts +1 -1
  53. package/dist/core/modules/controller/useWheelSwipe.js +2 -2
  54. package/dist/core/utils.d.ts +6 -1
  55. package/dist/core/utils.js +7 -3
  56. package/dist/plugins/captions/CaptionsContext.d.ts +2 -3
  57. package/dist/plugins/captions/CaptionsContext.js +2 -2
  58. package/dist/plugins/captions/Description.d.ts +3 -4
  59. package/dist/plugins/captions/Description.js +17 -13
  60. package/dist/plugins/captions/Title.d.ts +3 -4
  61. package/dist/plugins/captions/Title.js +2 -2
  62. package/dist/plugins/captions/utils.d.ts +1 -1
  63. package/dist/plugins/captions/utils.js +3 -1
  64. package/dist/plugins/fullscreen/FullscreenButton.d.ts +2 -2
  65. package/dist/plugins/fullscreen/FullscreenButton.js +2 -2
  66. package/dist/plugins/fullscreen/FullscreenContext.d.ts +4 -4
  67. package/dist/plugins/fullscreen/FullscreenContext.js +2 -2
  68. package/dist/plugins/fullscreen/index.d.ts +9 -8
  69. package/dist/plugins/inline/Inline.js +3 -1
  70. package/dist/plugins/slideshow/SlideshowButton.d.ts +2 -2
  71. package/dist/plugins/slideshow/SlideshowButton.js +2 -2
  72. package/dist/plugins/slideshow/SlideshowContext.d.ts +4 -4
  73. package/dist/plugins/slideshow/SlideshowContext.js +2 -2
  74. package/dist/plugins/slideshow/index.d.ts +12 -11
  75. package/dist/plugins/thumbnails/Thumbnail.d.ts +3 -4
  76. package/dist/plugins/thumbnails/Thumbnail.js +19 -17
  77. package/dist/plugins/thumbnails/ThumbnailsContainer.d.ts +3 -2
  78. package/dist/plugins/thumbnails/ThumbnailsContainer.js +2 -2
  79. package/dist/plugins/thumbnails/ThumbnailsTrack.d.ts +3 -4
  80. package/dist/plugins/thumbnails/ThumbnailsTrack.js +9 -4
  81. package/dist/plugins/thumbnails/index.d.ts +9 -7
  82. package/dist/plugins/video/VideoSlide.d.ts +3 -4
  83. package/dist/plugins/video/VideoSlide.js +2 -2
  84. package/dist/plugins/zoom/ResponsiveImage.d.ts +5 -6
  85. package/dist/plugins/zoom/ResponsiveImage.js +6 -3
  86. package/dist/plugins/zoom/ZoomButtonsGroup.d.ts +2 -2
  87. package/dist/plugins/zoom/ZoomButtonsGroup.js +2 -2
  88. package/dist/plugins/zoom/ZoomContainer.d.ts +5 -4
  89. package/dist/plugins/zoom/ZoomContainer.js +10 -10
  90. package/dist/plugins/zoom/ZoomContext.d.ts +4 -4
  91. package/dist/plugins/zoom/ZoomContext.js +2 -2
  92. package/dist/plugins/zoom/index.d.ts +12 -13
  93. package/dist/props.d.ts +4 -0
  94. package/dist/props.js +5 -4
  95. package/dist/styles.css +1 -0
  96. package/dist/types.d.ts +46 -26
  97. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { createModule } from "../config.js";
3
- import { cleanup, clsx, cssClass, cssVar, isNumber, makeComposePrefix, makeUseContext, parseLengthPercentage, } from "../utils.js";
3
+ import { cleanup, clsx, cssClass, cssVar, getAnimationEasing, getNavigationAnimationDuration, getSwipeAnimationDuration, isNumber, makeComposePrefix, makeUseContext, parseLengthPercentage, } from "../utils.js";
4
4
  import { useAnimation, useContainerRect, useDelay, useEventCallback, useForkRef, useRTL, useSensors, } from "../hooks/index.js";
5
5
  import { useEvents, useLightboxState } from "../contexts/index.js";
6
6
  import { SwipeState, usePointerSwipe, usePreventSwipeNavigation, useWheelSwipe } from "./controller/index.js";
@@ -8,7 +8,7 @@ import { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, CLASS_FLEX_CENTER
8
8
  const cssContainerPrefix = makeComposePrefix("container");
9
9
  const ControllerContext = React.createContext(null);
10
10
  export const useController = makeUseContext("useController", "ControllerContext", ControllerContext);
11
- export const Controller = ({ children, ...props }) => {
11
+ export function Controller({ children, ...props }) {
12
12
  const { carousel, slides, animation, controller, on, styles } = props;
13
13
  const { state, dispatch } = useLightboxState();
14
14
  const [swipeState, setSwipeState] = React.useState(SwipeState.NONE);
@@ -48,16 +48,20 @@ export const Controller = ({ children, ...props }) => {
48
48
  { transform: "translateX(0)" },
49
49
  ],
50
50
  duration: state.animation.duration,
51
+ easing: state.animation.easing,
51
52
  };
52
53
  }
53
54
  return undefined;
54
55
  });
55
56
  const swipe = useEventCallback((action) => {
56
- var _a, _b;
57
+ var _a;
57
58
  const currentSwipeOffset = action.offset || 0;
58
- const swipeDuration = (_a = (!currentSwipeOffset ? animation.navigation : undefined)) !== null && _a !== void 0 ? _a : animation.swipe;
59
+ const swipeDuration = !currentSwipeOffset
60
+ ? getNavigationAnimationDuration(animation)
61
+ : getSwipeAnimationDuration(animation);
62
+ const swipeEasing = getAnimationEasing(!currentSwipeOffset ? animation.navigation : animation.swipe);
59
63
  let { direction } = action;
60
- const count = (_b = action.count) !== null && _b !== void 0 ? _b : 1;
64
+ const count = (_a = action.count) !== null && _a !== void 0 ? _a : 1;
61
65
  let newSwipeState = SwipeState.ANIMATION;
62
66
  let newSwipeAnimationDuration = swipeDuration * count;
63
67
  if (!direction) {
@@ -75,13 +79,11 @@ export const Controller = ({ children, ...props }) => {
75
79
  newSwipeAnimationDuration =
76
80
  (swipeDuration / containerWidth) * (containerWidth - Math.abs(currentSwipeOffset));
77
81
  }
82
+ direction = rtl(currentSwipeOffset) > 0 ? ACTION_PREV : ACTION_NEXT;
78
83
  }
79
84
  else {
80
85
  newSwipeAnimationDuration = swipeDuration / 2;
81
86
  }
82
- if (count !== 0) {
83
- direction = rtl(currentSwipeOffset) > 0 ? ACTION_PREV : ACTION_NEXT;
84
- }
85
87
  }
86
88
  let increment = 0;
87
89
  if (direction === ACTION_PREV) {
@@ -114,7 +116,7 @@ export const Controller = ({ children, ...props }) => {
114
116
  });
115
117
  }
116
118
  setSwipeState(newSwipeState);
117
- publish(ACTION_SWIPE, { increment, duration: newSwipeAnimationDuration });
119
+ publish(ACTION_SWIPE, { increment, duration: newSwipeAnimationDuration, easing: swipeEasing });
118
120
  });
119
121
  React.useEffect(() => {
120
122
  var _a, _b;
@@ -126,7 +128,7 @@ export const Controller = ({ children, ...props }) => {
126
128
  subscribeSensors,
127
129
  isSwipeValid,
128
130
  (containerRect === null || containerRect === void 0 ? void 0 : containerRect.width) || 0,
129
- animation.swipe,
131
+ getSwipeAnimationDuration(animation),
130
132
  () => setSwipeState(SwipeState.SWIPE),
131
133
  (offset) => setSwipeOffset(offset),
132
134
  (offset, duration) => swipe({ offset, duration, count: 1 }),
@@ -174,5 +176,5 @@ export const Controller = ({ children, ...props }) => {
174
176
  : null),
175
177
  ...styles.container,
176
178
  }, ...(controller.aria ? { role: "presentation", "aria-live": "polite" } : null), tabIndex: -1, ...registerSensors }, containerRect && React.createElement(ControllerContext.Provider, { value: context }, children)));
177
- };
179
+ }
178
180
  export const ControllerModule = createModule(MODULE_CONTROLLER, Controller);
@@ -1,3 +1,4 @@
1
- import { Component } from "../../types.js";
2
- export declare const Core: Component;
1
+ /// <reference types="react" />
2
+ import { ComponentProps } from "../../types.js";
3
+ export declare function Core({ slides, index, children }: ComponentProps): JSX.Element;
3
4
  export declare const CoreModule: import("../../types.js").Module;
@@ -2,7 +2,9 @@ import * as React from "react";
2
2
  import { createModule } from "../config.js";
3
3
  import { EventsProvider, LightboxStateProvider, TimeoutsProvider } from "../contexts/index.js";
4
4
  import { MODULE_CORE } from "../consts.js";
5
- export const Core = ({ slides, index, children }) => (React.createElement(TimeoutsProvider, null,
6
- React.createElement(EventsProvider, null,
7
- React.createElement(LightboxStateProvider, { slidesCount: slides.length, initialIndex: index }, children))));
5
+ export function Core({ slides, index, children }) {
6
+ return (React.createElement(TimeoutsProvider, null,
7
+ React.createElement(EventsProvider, null,
8
+ React.createElement(LightboxStateProvider, { slidesCount: slides.length, initialIndex: index }, children))));
9
+ }
8
10
  export const CoreModule = createModule(MODULE_CORE, Core);
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { Component, Labels } from "../../types.js";
2
+ import { ComponentProps, Labels } from "../../types.js";
3
3
  export type NavigationButtonProps = {
4
4
  labels?: Labels;
5
5
  label: string;
@@ -9,6 +9,6 @@ export type NavigationButtonProps = {
9
9
  onClick: () => void;
10
10
  disabled?: boolean;
11
11
  };
12
- export declare const NavigationButton: ({ labels, label, icon, renderIcon, action, onClick, disabled, }: NavigationButtonProps) => JSX.Element;
13
- export declare const Navigation: Component;
12
+ export declare function NavigationButton({ labels, label, icon, renderIcon, action, onClick, disabled, }: NavigationButtonProps): JSX.Element;
13
+ export declare function Navigation({ slides, carousel: { finite }, animation, labels, render: { buttonPrev, buttonNext, iconPrev, iconNext }, }: ComponentProps): JSX.Element;
14
14
  export declare const NavigationModule: import("../../types.js").Module;
@@ -1,20 +1,22 @@
1
1
  import * as React from "react";
2
2
  import { createModule } from "../config.js";
3
3
  import { useEventCallback, useLoseFocus, useRTL, useThrottle } from "../hooks/index.js";
4
- import { cssClass, label as translateLabel } from "../utils.js";
4
+ import { cssClass, getNavigationAnimationDuration, label as translateLabel } from "../utils.js";
5
5
  import { IconButton, NextIcon, PreviousIcon } from "../components/index.js";
6
6
  import { useEvents, useLightboxState } from "../contexts/index.js";
7
7
  import { useController } from "./Controller.js";
8
8
  import { ACTION_NEXT, ACTION_PREV, EVENT_ON_KEY_DOWN, MODULE_NAVIGATION, VK_ARROW_LEFT, VK_ARROW_RIGHT, } from "../consts.js";
9
- export const NavigationButton = ({ labels, label, icon, renderIcon, action, onClick, disabled, }) => (React.createElement(IconButton, { label: translateLabel(labels, label), icon: icon, renderIcon: renderIcon, className: cssClass(`navigation_${action}`), disabled: disabled, onClick: onClick, ...useLoseFocus(disabled) }));
10
- export const Navigation = ({ slides, carousel: { finite }, animation: { swipe, navigation }, labels, render: { buttonPrev, buttonNext, iconPrev, iconNext }, }) => {
9
+ export function NavigationButton({ labels, label, icon, renderIcon, action, onClick, disabled, }) {
10
+ return (React.createElement(IconButton, { label: translateLabel(labels, label), icon: icon, renderIcon: renderIcon, className: cssClass(`navigation_${action}`), disabled: disabled, onClick: onClick, ...useLoseFocus(disabled) }));
11
+ }
12
+ export function Navigation({ slides, carousel: { finite }, animation, labels, render: { buttonPrev, buttonNext, iconPrev, iconNext }, }) {
11
13
  const { currentIndex } = useLightboxState().state;
12
14
  const { subscribeSensors } = useController();
13
15
  const { publish } = useEvents();
14
16
  const isRTL = useRTL();
15
17
  const prevDisabled = slides.length === 0 || (finite && currentIndex === 0);
16
18
  const nextDisabled = slides.length === 0 || (finite && currentIndex === slides.length - 1);
17
- const publishThrottled = useThrottle((action) => publish(action), (navigation !== null && navigation !== void 0 ? navigation : swipe) / 2);
19
+ const publishThrottled = useThrottle((action) => publish(action), getNavigationAnimationDuration(animation) / 2);
18
20
  const handleKeyDown = useEventCallback((event) => {
19
21
  if (event.key === VK_ARROW_LEFT && !(isRTL ? nextDisabled : prevDisabled)) {
20
22
  publishThrottled(isRTL ? ACTION_NEXT : ACTION_PREV);
@@ -27,5 +29,5 @@ export const Navigation = ({ slides, carousel: { finite }, animation: { swipe, n
27
29
  return (React.createElement(React.Fragment, null,
28
30
  buttonPrev ? (buttonPrev()) : (React.createElement(NavigationButton, { label: "Previous", action: ACTION_PREV, icon: PreviousIcon, renderIcon: iconPrev, disabled: prevDisabled, labels: labels, onClick: () => publish(ACTION_PREV) })),
29
31
  buttonNext ? (buttonNext()) : (React.createElement(NavigationButton, { label: "Next", action: ACTION_NEXT, icon: NextIcon, renderIcon: iconNext, disabled: nextDisabled, labels: labels, onClick: () => publish(ACTION_NEXT) }))));
30
- };
32
+ }
31
33
  export const NavigationModule = createModule(MODULE_NAVIGATION, Navigation);
@@ -1,3 +1,4 @@
1
- import { Component } from "../../types.js";
2
- export declare const NoScroll: Component;
1
+ /// <reference types="react" />
2
+ import { ComponentProps } from "../../types.js";
3
+ export declare function NoScroll({ children }: ComponentProps): JSX.Element;
3
4
  export declare const NoScrollModule: import("../../types.js").Module;
@@ -5,8 +5,10 @@ import { useLayoutEffect, useRTL } from "../hooks/index.js";
5
5
  import { CLASS_NO_SCROLL, CLASS_NO_SCROLL_PADDING, MODULE_NO_SCROLL } from "../consts.js";
6
6
  const noScroll = cssClass(CLASS_NO_SCROLL);
7
7
  const noScrollPadding = cssClass(CLASS_NO_SCROLL_PADDING);
8
- const isHTMLElement = (element) => "style" in element;
9
- const padScrollbar = (element, padding, rtl) => {
8
+ function isHTMLElement(element) {
9
+ return "style" in element;
10
+ }
11
+ function padScrollbar(element, padding, rtl) {
10
12
  const styles = window.getComputedStyle(element);
11
13
  const property = rtl ? "padding-left" : "padding-right";
12
14
  const computedValue = rtl ? styles.paddingLeft : styles.paddingRight;
@@ -20,8 +22,8 @@ const padScrollbar = (element, padding, rtl) => {
20
22
  element.style.removeProperty(property);
21
23
  }
22
24
  };
23
- };
24
- export const NoScroll = ({ children }) => {
25
+ }
26
+ export function NoScroll({ children }) {
25
27
  const rtl = useRTL();
26
28
  useLayoutEffect(() => {
27
29
  const cleanup = [];
@@ -46,5 +48,5 @@ export const NoScroll = ({ children }) => {
46
48
  };
47
49
  }, [rtl]);
48
50
  return React.createElement(React.Fragment, null, children);
49
- };
51
+ }
50
52
  export const NoScrollModule = createModule(MODULE_NO_SCROLL, NoScroll);
@@ -1,3 +1,4 @@
1
- import { Component } from "../../types.js";
2
- export declare const Portal: Component;
1
+ import * as React from "react";
2
+ import { ComponentProps } from "../../types.js";
3
+ export declare function Portal({ children, animation, styles, className, on, close }: ComponentProps): React.ReactPortal | null;
3
4
  export declare const PortalModule: import("../../types.js").Module;
@@ -2,12 +2,14 @@ import * as React from "react";
2
2
  import * as ReactDOM from "react-dom";
3
3
  import { LightboxDefaultProps } from "../../props.js";
4
4
  import { createModule } from "../config.js";
5
- import { clsx, composePrefix, cssClass, cssVar } from "../utils.js";
5
+ import { clsx, composePrefix, cssClass, cssVar, getAnimationEasing, getFadeAnimationDuration } from "../utils.js";
6
6
  import { useEventCallback, useMotionPreference } from "../hooks/index.js";
7
7
  import { useEvents, useTimeouts } from "../contexts/index.js";
8
8
  import { ACTION_CLOSE, CLASS_NO_SCROLL_PADDING, MODULE_PORTAL } from "../consts.js";
9
- const cssPrefix = (value) => composePrefix(MODULE_PORTAL, value);
10
- const setAttribute = (element, attribute, value) => {
9
+ function cssPrefix(value) {
10
+ return composePrefix(MODULE_PORTAL, value);
11
+ }
12
+ function setAttribute(element, attribute, value) {
11
13
  const previousValue = element.getAttribute(attribute);
12
14
  element.setAttribute(attribute, value);
13
15
  return () => {
@@ -18,14 +20,16 @@ const setAttribute = (element, attribute, value) => {
18
20
  element.removeAttribute(attribute);
19
21
  }
20
22
  };
21
- };
22
- export const Portal = ({ children, animation, styles, className, on, close }) => {
23
+ }
24
+ export function Portal({ children, animation, styles, className, on, close }) {
23
25
  const [mounted, setMounted] = React.useState(false);
24
26
  const [visible, setVisible] = React.useState(false);
25
27
  const cleanup = React.useRef([]);
26
28
  const { setTimeout } = useTimeouts();
27
29
  const { subscribe } = useEvents();
28
- const fadeAnimationDuration = !useMotionPreference() ? animation.fade : 0;
30
+ const reduceMotion = useMotionPreference();
31
+ const animationDuration = !reduceMotion ? getFadeAnimationDuration(animation) : 0;
32
+ const animationEasing = !reduceMotion ? getAnimationEasing(animation.fade) : undefined;
29
33
  React.useEffect(() => {
30
34
  setMounted(true);
31
35
  return () => {
@@ -41,7 +45,7 @@ export const Portal = ({ children, animation, styles, className, on, close }) =>
41
45
  var _a;
42
46
  (_a = on.exited) === null || _a === void 0 ? void 0 : _a.call(on);
43
47
  close();
44
- }, fadeAnimationDuration);
48
+ }, animationDuration);
45
49
  });
46
50
  React.useEffect(() => subscribe(ACTION_CLOSE, handleClose), [subscribe, handleClose]);
47
51
  const handleEnter = useEventCallback((node) => {
@@ -60,7 +64,7 @@ export const Portal = ({ children, animation, styles, className, on, close }) =>
60
64
  setTimeout(() => {
61
65
  var _a;
62
66
  (_a = on.entered) === null || _a === void 0 ? void 0 : _a.call(on);
63
- }, fadeAnimationDuration);
67
+ }, animationDuration);
64
68
  });
65
69
  const handleExit = useEventCallback(() => {
66
70
  cleanup.current.forEach((clean) => clean());
@@ -77,12 +81,11 @@ export const Portal = ({ children, animation, styles, className, on, close }) =>
77
81
  return mounted
78
82
  ? ReactDOM.createPortal(React.createElement("div", { ref: handleRef, className: clsx(className, cssClass("root"), cssClass(cssPrefix()), cssClass(CLASS_NO_SCROLL_PADDING), visible && cssClass(cssPrefix("open"))), role: "presentation", "aria-live": "polite", style: {
79
83
  ...(animation.fade !== LightboxDefaultProps.animation.fade
80
- ? {
81
- [cssVar("fade_animation_duration")]: `${fadeAnimationDuration}ms`,
82
- }
84
+ ? { [cssVar("fade_animation_duration")]: `${animationDuration}ms` }
83
85
  : null),
86
+ ...(animationEasing ? { [cssVar("fade_animation_timing_function")]: animationEasing } : null),
84
87
  ...styles.root,
85
88
  } }, children), document.body)
86
89
  : null;
87
- };
90
+ }
88
91
  export const PortalModule = createModule(MODULE_PORTAL, Portal);
@@ -1,9 +1,10 @@
1
- import { Component } from "../../types.js";
1
+ /// <reference types="react" />
2
+ import { ComponentProps } from "../../types.js";
2
3
  import { YARL_EVENT_TOOLBAR_WIDTH } from "../consts.js";
3
4
  declare module "../" {
4
5
  interface EventTypes {
5
6
  [YARL_EVENT_TOOLBAR_WIDTH]: number;
6
7
  }
7
8
  }
8
- export declare const Toolbar: Component;
9
+ export declare function Toolbar({ toolbar: { buttons }, labels, render: { buttonClose, iconClose } }: ComponentProps): JSX.Element;
9
10
  export declare const ToolbarModule: import("../../types.js").Module;
@@ -5,8 +5,10 @@ import { useEvents } from "../contexts/index.js";
5
5
  import { CloseIcon, IconButton } from "../components/index.js";
6
6
  import { useContainerRect } from "../hooks/useContainerRect.js";
7
7
  import { ACTION_CLOSE, MODULE_TOOLBAR, YARL_EVENT_TOOLBAR_WIDTH } from "../consts.js";
8
- const cssPrefix = (value) => composePrefix(MODULE_TOOLBAR, value);
9
- export const Toolbar = ({ toolbar: { buttons }, labels, render: { buttonClose, iconClose } }) => {
8
+ function cssPrefix(value) {
9
+ return composePrefix(MODULE_TOOLBAR, value);
10
+ }
11
+ export function Toolbar({ toolbar: { buttons }, labels, render: { buttonClose, iconClose } }) {
10
12
  const { publish } = useEvents();
11
13
  const { setContainerRef, containerRect } = useContainerRect();
12
14
  React.useEffect(() => {
@@ -16,5 +18,5 @@ export const Toolbar = ({ toolbar: { buttons }, labels, render: { buttonClose, i
16
18
  }, [publish, containerRect === null || containerRect === void 0 ? void 0 : containerRect.width]);
17
19
  const renderCloseButton = () => buttonClose ? (buttonClose()) : (React.createElement(IconButton, { key: ACTION_CLOSE, label: label(labels, "Close"), icon: CloseIcon, renderIcon: iconClose, onClick: () => publish(ACTION_CLOSE) }));
18
20
  return (React.createElement("div", { ref: setContainerRef, className: cssClass(cssPrefix()) }, buttons === null || buttons === void 0 ? void 0 : buttons.map((button) => (button === ACTION_CLOSE ? renderCloseButton() : button))));
19
- };
21
+ }
20
22
  export const ToolbarModule = createModule(MODULE_TOOLBAR, Toolbar);
@@ -1,2 +1,2 @@
1
1
  import { UseSensors } from "../../hooks/useSensors.js";
2
- export declare const usePointerSwipe: <T extends Element = Element>(subscribeSensors: import("../../hooks/useSensors.js").SubscribeSensors<T>, isSwipeValid: (offset: number) => boolean, containerWidth: number, swipeAnimationDuration: number, onSwipeStart: () => void, onSwipeProgress: (offset: number) => void, onSwipeFinish: (offset: number, duration: number) => void, onSwipeCancel: (offset: number) => void) => void;
2
+ export declare function usePointerSwipe<T extends Element = Element>(subscribeSensors: UseSensors<T>["subscribeSensors"], isSwipeValid: (offset: number) => boolean, containerWidth: number, swipeAnimationDuration: number, onSwipeStart: () => void, onSwipeProgress: (offset: number) => void, onSwipeFinish: (offset: number, duration: number) => void, onSwipeCancel: (offset: number) => void): void;
@@ -2,7 +2,7 @@ import * as React from "react";
2
2
  import { cleanup } from "../../utils.js";
3
3
  import { useEventCallback } from "../../hooks/useEventCallback.js";
4
4
  import { EVENT_ON_POINTER_CANCEL, EVENT_ON_POINTER_DOWN, EVENT_ON_POINTER_LEAVE, EVENT_ON_POINTER_MOVE, EVENT_ON_POINTER_UP, } from "../../consts.js";
5
- export const usePointerSwipe = (subscribeSensors, isSwipeValid, containerWidth, swipeAnimationDuration, onSwipeStart, onSwipeProgress, onSwipeFinish, onSwipeCancel) => {
5
+ export function usePointerSwipe(subscribeSensors, isSwipeValid, containerWidth, swipeAnimationDuration, onSwipeStart, onSwipeProgress, onSwipeFinish, onSwipeCancel) {
6
6
  const offset = React.useRef(0);
7
7
  const pointers = React.useRef([]);
8
8
  const activePointer = React.useRef();
@@ -69,4 +69,4 @@ export const usePointerSwipe = (subscribeSensors, isSwipeValid, containerWidth,
69
69
  }
70
70
  });
71
71
  React.useEffect(() => cleanup(subscribeSensors(EVENT_ON_POINTER_DOWN, onPointerDown), subscribeSensors(EVENT_ON_POINTER_MOVE, onPointerMove), subscribeSensors(EVENT_ON_POINTER_UP, onPointerUp), subscribeSensors(EVENT_ON_POINTER_LEAVE, onPointerUp), subscribeSensors(EVENT_ON_POINTER_CANCEL, onPointerUp)), [subscribeSensors, onPointerDown, onPointerMove, onPointerUp]);
72
- };
72
+ }
@@ -1,3 +1,3 @@
1
1
  /** prevent browser back/forward navigation on touchpad left/right swipe (especially noticeable in Safari)
2
2
  * this has to be done via non-passive native event handler */
3
- export declare const usePreventSwipeNavigation: <T extends HTMLElement = HTMLElement>() => (node: T | null) => void;
3
+ export declare function usePreventSwipeNavigation<T extends HTMLElement = HTMLElement>(): (node: T | null) => void;
@@ -1,11 +1,11 @@
1
1
  import * as React from "react";
2
2
  const WHEEL = "wheel";
3
- const preventDefault = (event) => {
3
+ function preventDefault(event) {
4
4
  if (Math.abs(event.deltaX) > Math.abs(event.deltaY) || event.ctrlKey) {
5
5
  event.preventDefault();
6
6
  }
7
- };
8
- export const usePreventSwipeNavigation = () => {
7
+ }
8
+ export function usePreventSwipeNavigation() {
9
9
  const ref = React.useRef(null);
10
10
  return React.useCallback((node) => {
11
11
  var _a;
@@ -17,4 +17,4 @@ export const usePreventSwipeNavigation = () => {
17
17
  }
18
18
  ref.current = node;
19
19
  }, []);
20
- };
20
+ }
@@ -1,3 +1,3 @@
1
1
  import { UseSensors } from "../../hooks/index.js";
2
2
  import { SwipeState } from "./index.js";
3
- export declare const useWheelSwipe: <T extends Element = Element>(swipeState: SwipeState, subscribeSensors: import("../../hooks/useSensors.js").SubscribeSensors<T>, isSwipeValid: (offset: number) => boolean, containerWidth: number, swipeAnimationDuration: number, onSwipeStart: () => void, onSwipeProgress: (offset: number) => void, onSwipeFinish: (offset: number, duration: number) => void, onSwipeCancel: (offset: number) => void) => void;
3
+ export declare function useWheelSwipe<T extends Element = Element>(swipeState: SwipeState, subscribeSensors: UseSensors<T>["subscribeSensors"], isSwipeValid: (offset: number) => boolean, containerWidth: number, swipeAnimationDuration: number, onSwipeStart: () => void, onSwipeProgress: (offset: number) => void, onSwipeFinish: (offset: number, duration: number) => void, onSwipeCancel: (offset: number) => void): void;
@@ -3,7 +3,7 @@ import { useEventCallback } from "../../hooks/index.js";
3
3
  import { useTimeouts } from "../../contexts/index.js";
4
4
  import { SwipeState } from "./index.js";
5
5
  import { EVENT_ON_WHEEL } from "../../consts.js";
6
- export const useWheelSwipe = (swipeState, subscribeSensors, isSwipeValid, containerWidth, swipeAnimationDuration, onSwipeStart, onSwipeProgress, onSwipeFinish, onSwipeCancel) => {
6
+ export function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidth, swipeAnimationDuration, onSwipeStart, onSwipeProgress, onSwipeFinish, onSwipeCancel) {
7
7
  const offset = React.useRef(0);
8
8
  const intent = React.useRef(0);
9
9
  const intentCleanup = React.useRef();
@@ -89,4 +89,4 @@ export const useWheelSwipe = (swipeState, subscribeSensors, isSwipeValid, contai
89
89
  }
90
90
  });
91
91
  React.useEffect(() => subscribeSensors(EVENT_ON_WHEEL, onWheel), [subscribeSensors, onWheel]);
92
- };
92
+ }
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { Labels, Slide, SlideImage } from "../types.js";
2
+ import { AnimationSettings, AnimationSpec, Labels, Slide, SlideImage } from "../types.js";
3
3
  export declare const clsx: (...classes: (string | boolean | undefined)[]) => string;
4
4
  export declare const cssClass: (name: string) => string;
5
5
  export declare const cssVar: (name: string) => string;
@@ -23,3 +23,8 @@ export declare const parseLengthPercentage: (input: unknown) => {
23
23
  export declare const devicePixelRatio: () => number;
24
24
  export declare const getSlideIndex: (index: number, slidesCount: number) => number;
25
25
  export declare const getSlide: (slides: Slide[], index: number) => Slide;
26
+ export declare const getAnimationEasing: (animationSpec: AnimationSpec | undefined) => string | undefined;
27
+ export declare const getAnimationDuration: (animationSpec: AnimationSpec | undefined, defaultDuration: number) => number;
28
+ export declare const getFadeAnimationDuration: (animation: AnimationSettings) => number;
29
+ export declare const getSwipeAnimationDuration: (animation: AnimationSettings) => number;
30
+ export declare const getNavigationAnimationDuration: (animation: AnimationSettings) => number;
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
+ import { AnimationDefaultProps } from "../props.js";
2
3
  export const clsx = (...classes) => [...classes].filter((cls) => Boolean(cls)).join(" ");
3
4
  const cssPrefix = "yarl__";
4
5
  export const cssClass = (name) => `${cssPrefix}${name}`;
@@ -36,8 +37,11 @@ export const parseLengthPercentage = (input) => {
36
37
  }
37
38
  return { pixel: 0 };
38
39
  };
39
- export const devicePixelRatio = () => {
40
- return (typeof window !== "undefined" ? window === null || window === void 0 ? void 0 : window.devicePixelRatio : undefined) || 1;
41
- };
40
+ export const devicePixelRatio = () => (typeof window !== "undefined" ? window === null || window === void 0 ? void 0 : window.devicePixelRatio : undefined) || 1;
42
41
  export const getSlideIndex = (index, slidesCount) => ((index % slidesCount) + slidesCount) % slidesCount;
43
42
  export const getSlide = (slides, index) => slides[getSlideIndex(index, slides.length)];
43
+ export const getAnimationEasing = (animationSpec) => typeof animationSpec === "object" ? animationSpec.easing : undefined;
44
+ export const getAnimationDuration = (animationSpec, defaultDuration) => { var _a; return (_a = (typeof animationSpec === "object" ? animationSpec.duration : animationSpec)) !== null && _a !== void 0 ? _a : defaultDuration; };
45
+ export const getFadeAnimationDuration = (animation) => getAnimationDuration(animation.fade, AnimationDefaultProps.fade);
46
+ export const getSwipeAnimationDuration = (animation) => getAnimationDuration(animation.swipe, AnimationDefaultProps.swipe);
47
+ export const getNavigationAnimationDuration = (animation) => getAnimationDuration(animation.navigation, getSwipeAnimationDuration(animation));
@@ -1,8 +1,7 @@
1
1
  import * as React from "react";
2
- type CaptionsContextType = {
2
+ export type CaptionsContextType = {
3
3
  toolbarWidth?: number;
4
4
  };
5
5
  export declare const useCaptions: () => CaptionsContextType;
6
6
  /** Captions plugin context holder */
7
- export declare const CaptionsContextProvider: React.FC<React.PropsWithChildren>;
8
- export {};
7
+ export declare function CaptionsContextProvider({ children }: React.PropsWithChildren): JSX.Element;
@@ -2,10 +2,10 @@ import * as React from "react";
2
2
  import { makeUseContext, useEvents, YARL_EVENT_TOOLBAR_WIDTH } from "../../core/index.js";
3
3
  const CaptionsContext = React.createContext(null);
4
4
  export const useCaptions = makeUseContext("useCaptions", "CaptionsContext", CaptionsContext);
5
- export const CaptionsContextProvider = ({ children }) => {
5
+ export function CaptionsContextProvider({ children }) {
6
6
  const { subscribe } = useEvents();
7
7
  const [toolbarWidth, setToolbarWidth] = React.useState();
8
8
  React.useEffect(() => subscribe(YARL_EVENT_TOOLBAR_WIDTH, (event) => setToolbarWidth(event)), [subscribe]);
9
9
  const context = React.useMemo(() => ({ toolbarWidth }), [toolbarWidth]);
10
10
  return React.createElement(CaptionsContext.Provider, { value: context }, children);
11
- };
11
+ }
@@ -1,5 +1,4 @@
1
- import * as React from "react";
1
+ /// <reference types="react" />
2
2
  import { LightboxProps, Slide } from "../../types.js";
3
- type DescriptionProps = Pick<LightboxProps, "styles"> & Required<Pick<Slide, "description">> & Required<LightboxProps["captions"]>;
4
- export declare const Description: React.FC<DescriptionProps>;
5
- export {};
3
+ export type DescriptionProps = Pick<LightboxProps, "styles"> & Required<Pick<Slide, "description">> & Required<LightboxProps["captions"]>;
4
+ export declare function Description({ description, descriptionTextAlign, descriptionMaxLines, styles }: DescriptionProps): JSX.Element;
@@ -2,16 +2,20 @@ import * as React from "react";
2
2
  import { clsx, cssVar } from "../../core/index.js";
3
3
  import { defaultCaptionsProps } from "./Captions.js";
4
4
  import { cssPrefix } from "./utils.js";
5
- export const Description = ({ description, descriptionTextAlign, descriptionMaxLines, styles, }) => (React.createElement("div", { style: styles.captionsDescriptionContainer, className: clsx(cssPrefix("captions_container"), cssPrefix("description_container")) },
6
- React.createElement("div", { className: cssPrefix("description"), style: {
7
- ...(descriptionTextAlign !== defaultCaptionsProps.descriptionTextAlign ||
8
- descriptionMaxLines !== defaultCaptionsProps.descriptionMaxLines
9
- ? {
10
- [cssVar("slide_description_text_align")]: descriptionTextAlign,
11
- [cssVar("slide_description_max_lines")]: descriptionMaxLines,
12
- }
13
- : null),
14
- ...styles.captionsDescription,
15
- } }, typeof description === "string"
16
- ? description.split("\n").flatMap((line, index) => [...(index > 0 ? [React.createElement("br", { key: index })] : []), line])
17
- : description)));
5
+ export function Description({ description, descriptionTextAlign, descriptionMaxLines, styles }) {
6
+ return (React.createElement("div", { style: styles.captionsDescriptionContainer, className: clsx(cssPrefix("captions_container"), cssPrefix("description_container")) },
7
+ React.createElement("div", { className: cssPrefix("description"), style: {
8
+ ...(descriptionTextAlign !== defaultCaptionsProps.descriptionTextAlign ||
9
+ descriptionMaxLines !== defaultCaptionsProps.descriptionMaxLines
10
+ ? {
11
+ [cssVar("slide_description_text_align")]: descriptionTextAlign,
12
+ [cssVar("slide_description_max_lines")]: descriptionMaxLines,
13
+ }
14
+ : null),
15
+ ...styles.captionsDescription,
16
+ } }, typeof description === "string"
17
+ ? description
18
+ .split("\n")
19
+ .flatMap((line, index) => [...(index > 0 ? [React.createElement("br", { key: index })] : []), line])
20
+ : description)));
21
+ }
@@ -1,5 +1,4 @@
1
- import * as React from "react";
1
+ /// <reference types="react" />
2
2
  import { LightboxProps, Slide } from "../../types.js";
3
- type TitleProps = Pick<LightboxProps, "styles"> & Pick<Slide, "title">;
4
- export declare const Title: React.FC<TitleProps>;
5
- export {};
3
+ export type TitleProps = Pick<LightboxProps, "styles"> & Pick<Slide, "title">;
4
+ export declare function Title({ title, styles }: TitleProps): JSX.Element;
@@ -2,8 +2,8 @@ import * as React from "react";
2
2
  import { clsx, cssVar } from "../../core/index.js";
3
3
  import { useCaptions } from "./CaptionsContext.js";
4
4
  import { cssPrefix } from "./utils.js";
5
- export const Title = ({ title, styles }) => {
5
+ export function Title({ title, styles }) {
6
6
  const { toolbarWidth } = useCaptions();
7
7
  return (React.createElement("div", { style: styles.captionsTitleContainer, className: clsx(cssPrefix("captions_container"), cssPrefix("title_container")) },
8
8
  React.createElement("div", { style: styles.captionsTitle, className: cssPrefix("title"), ...(toolbarWidth ? { style: { [cssVar("toolbar_width")]: `${toolbarWidth}px` } } : null) }, title)));
9
- };
9
+ }
@@ -1 +1 @@
1
- export declare const cssPrefix: (className: string) => string;
1
+ export declare function cssPrefix(className: string): string;
@@ -1,2 +1,4 @@
1
1
  import { cssClass } from "../../core/index.js";
2
- export const cssPrefix = (className) => cssClass(`slide_${className}`);
2
+ export function cssPrefix(className) {
3
+ return cssClass(`slide_${className}`);
4
+ }
@@ -1,3 +1,3 @@
1
- import * as React from "react";
1
+ /// <reference types="react" />
2
2
  /** Fullscreen button */
3
- export declare const FullscreenButton: React.FC;
3
+ export declare function FullscreenButton(): JSX.Element | null;
@@ -3,11 +3,11 @@ import { createIcon, IconButton, label, useController } from "../../core/index.j
3
3
  import { useFullscreen } from "./FullscreenContext.js";
4
4
  const EnterFullscreenIcon = createIcon("EnterFullscreen", React.createElement("path", { d: "M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z" }));
5
5
  const ExitFullscreenIcon = createIcon("ExitFullscreen", React.createElement("path", { d: "M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z" }));
6
- export const FullscreenButton = () => {
6
+ export function FullscreenButton() {
7
7
  var _a;
8
8
  const { labels, render } = useController().getLightboxProps();
9
9
  const { fullscreen, fullscreenEnabled, toggleFullscreen } = useFullscreen();
10
10
  if (!fullscreenEnabled)
11
11
  return null;
12
12
  return render.buttonFullscreen ? (React.createElement(React.Fragment, null, (_a = render.buttonFullscreen) === null || _a === void 0 ? void 0 : _a.call(render, { fullscreen, fullscreenEnabled, toggleFullscreen }))) : (React.createElement(IconButton, { disabled: !fullscreenEnabled, label: fullscreen ? label(labels, "Exit Fullscreen") : label(labels, "Enter Fullscreen"), icon: fullscreen ? ExitFullscreenIcon : EnterFullscreenIcon, renderIcon: fullscreen ? render.iconExitFullscreen : render.iconEnterFullscreen, onClick: toggleFullscreen }));
13
- };
13
+ }
@@ -1,9 +1,9 @@
1
- import { Component } from "../../types.js";
2
- type FullscreenContextType = {
1
+ /// <reference types="react" />
2
+ import { ComponentProps } from "../../types.js";
3
+ export type FullscreenContextType = {
3
4
  fullscreen: boolean;
4
5
  fullscreenEnabled?: boolean;
5
6
  toggleFullscreen: () => void;
6
7
  };
7
8
  export declare const useFullscreen: () => FullscreenContextType;
8
- export declare const FullscreenContextProvider: Component;
9
- export {};
9
+ export declare function FullscreenContextProvider({ fullscreen: auto, children }: ComponentProps): JSX.Element;
@@ -2,7 +2,7 @@ import * as React from "react";
2
2
  import { CLASS_FULLSIZE, clsx, cssClass, makeUseContext, PLUGIN_FULLSCREEN, useEventCallback, useLayoutEffect, } from "../../core/index.js";
3
3
  const FullscreenContext = React.createContext(null);
4
4
  export const useFullscreen = makeUseContext("useFullscreen", "FullscreenContext", FullscreenContext);
5
- export const FullscreenContextProvider = ({ fullscreen: auto, children }) => {
5
+ export function FullscreenContextProvider({ fullscreen: auto, children }) {
6
6
  const containerRef = React.useRef(null);
7
7
  const [fullscreen, setFullscreen] = React.useState(false);
8
8
  const [fullscreenEnabled, setFullscreenEnabled] = React.useState();
@@ -100,4 +100,4 @@ export const FullscreenContextProvider = ({ fullscreen: auto, children }) => {
100
100
  }), [fullscreen, fullscreenEnabled, toggleFullscreen]);
101
101
  return (React.createElement("div", { ref: containerRef, className: clsx(cssClass(PLUGIN_FULLSCREEN), cssClass(CLASS_FULLSIZE)) },
102
102
  React.createElement(FullscreenContext.Provider, { value: context }, children)));
103
- };
103
+ }
@@ -1,21 +1,22 @@
1
- import * as React from "react";
2
1
  import { Fullscreen } from "./Fullscreen.js";
3
2
  declare module "../../types" {
4
3
  interface LightboxProps {
5
4
  /** if `true`, enter fullscreen mode automatically when the lightbox opens */
6
5
  fullscreen?: boolean;
7
6
  }
7
+ /** `render.buttonFullscreen` render function props */
8
+ type RenderFullscreenButtonProps = {
9
+ fullscreen: boolean;
10
+ fullscreenEnabled: boolean | undefined;
11
+ toggleFullscreen: () => void;
12
+ };
8
13
  interface Render {
9
14
  /** render custom Enter/Exit Fullscreen button */
10
- buttonFullscreen?: ({ fullscreen, fullscreenEnabled, toggleFullscreen, }: {
11
- fullscreen: boolean;
12
- fullscreenEnabled: boolean | undefined;
13
- toggleFullscreen: () => void;
14
- }) => React.ReactNode;
15
+ buttonFullscreen?: RenderFunction<RenderFullscreenButtonProps>;
15
16
  /** render custom Enter Fullscreen icon */
16
- iconEnterFullscreen?: () => React.ReactNode;
17
+ iconEnterFullscreen?: RenderFunction;
17
18
  /** render custom Exit Fullscreen icon */
18
- iconExitFullscreen?: () => React.ReactNode;
19
+ iconExitFullscreen?: RenderFunction;
19
20
  }
20
21
  }
21
22
  declare global {