yet-another-react-lightbox 2.6.0 → 2.6.2

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 (95) 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 +5 -5
  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 +2 -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 +1 -1
  15. package/dist/core/hooks/useAnimation.js +4 -4
  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 +2 -2
  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 +6 -4
  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 +7 -5
  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 +2 -1
  55. package/dist/core/utils.js +4 -6
  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 +8 -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 +8 -5
  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 +11 -15
  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/styles.css +1 -0
  94. package/dist/types.d.ts +31 -20
  95. package/package.json +1 -1
package/README.md CHANGED
@@ -49,7 +49,7 @@ import * as React from "react";
49
49
  import Lightbox from "yet-another-react-lightbox";
50
50
  import "yet-another-react-lightbox/styles.css";
51
51
 
52
- const App = () => {
52
+ export default function App() {
53
53
  const [open, setOpen] = React.useState(false);
54
54
 
55
55
  return (
@@ -69,9 +69,7 @@ const App = () => {
69
69
  />
70
70
  </>
71
71
  );
72
- };
73
-
74
- export default App;
72
+ }
75
73
  ```
76
74
 
77
75
  ## Recommended Setup
@@ -86,7 +84,7 @@ import * as React from "react";
86
84
  import Lightbox from "yet-another-react-lightbox";
87
85
  import "yet-another-react-lightbox/styles.css";
88
86
 
89
- const App = () => {
87
+ export default function App() {
90
88
  const [open, setOpen] = React.useState(false);
91
89
 
92
90
  return (
@@ -117,9 +115,7 @@ const App = () => {
117
115
  />
118
116
  </>
119
117
  );
120
- };
121
-
122
- export default App;
118
+ }
123
119
  ```
124
120
 
125
121
  You can also integrate 3rd-party image components (e.g., Next.js Image or Gatsby Image) via a custom render function.
@@ -1,4 +1,4 @@
1
- import * as React from "react";
1
+ /// <reference types="react" />
2
2
  import { LightboxExternalProps } from "./types.js";
3
3
  /** Lightbox component */
4
- export declare const Lightbox: React.FC<LightboxExternalProps>;
4
+ export declare function Lightbox(props: LightboxExternalProps): JSX.Element | null;
package/dist/Lightbox.js CHANGED
@@ -1,16 +1,18 @@
1
1
  import * as React from "react";
2
2
  import { LightboxDefaultProps } from "./props.js";
3
3
  import { CarouselModule, ControllerModule, CoreModule, createNode, NavigationModule, NoScrollModule, PortalModule, ToolbarModule, withPlugins, } from "./core/index.js";
4
- const renderNode = (node, props) => {
4
+ function renderNode(node, props) {
5
5
  var _a;
6
6
  return React.createElement(node.module.component, { key: node.module.name, ...props }, (_a = node.children) === null || _a === void 0 ? void 0 : _a.map((child) => renderNode(child, props)));
7
- };
8
- const fixupIndex = ({ index, slides, ...rest }) => ({
9
- index: index >= 0 && index < slides.length ? index : 0,
10
- slides,
11
- ...rest,
12
- });
13
- export const Lightbox = (props) => {
7
+ }
8
+ function fixupIndex({ index, slides, ...rest }) {
9
+ return {
10
+ index: index >= 0 && index < slides.length ? index : 0,
11
+ slides,
12
+ ...rest,
13
+ };
14
+ }
15
+ export function Lightbox(props) {
14
16
  const { carousel, animation, render, toolbar, controller, on, plugins, ...restProps } = props;
15
17
  const { carousel: defaultCarousel, animation: defaultAnimation, render: defaultRender, toolbar: defaultToolbar, controller: defaultController, on: defaultOn, ...restDefaultProps } = LightboxDefaultProps;
16
18
  const { config, augmentation } = withPlugins([
@@ -37,4 +39,4 @@ export const Lightbox = (props) => {
37
39
  if (!augmentedProps.open)
38
40
  return null;
39
41
  return React.createElement(React.Fragment, null, renderNode(createNode(CoreModule, config), augmentedProps));
40
- };
42
+ }
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- export declare const createIcon: (name: string, glyph: React.ReactNode) => {
2
+ export declare function createIcon(name: string, glyph: React.ReactNode): {
3
3
  (props: React.SVGProps<SVGSVGElement>): JSX.Element;
4
4
  displayName: string;
5
5
  };
@@ -1,12 +1,12 @@
1
1
  import * as React from "react";
2
- export const createIcon = (name, glyph) => {
2
+ export function createIcon(name, glyph) {
3
3
  const icon = (props) => (React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "24", height: "24", "aria-hidden": "true", focusable: "false", ...props },
4
4
  React.createElement("g", { fill: "currentColor" },
5
5
  React.createElement("path", { d: "M0 0h24v24H0z", fill: "none" }),
6
6
  glyph)));
7
7
  icon.displayName = name;
8
8
  return icon;
9
- };
9
+ }
10
10
  export const CloseIcon = createIcon("Close", React.createElement("path", { d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" }));
11
11
  export const PreviousIcon = createIcon("Previous", React.createElement("path", { d: "M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z" }));
12
12
  export const NextIcon = createIcon("Next", React.createElement("path", { d: "M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z" }));
@@ -10,4 +10,4 @@ export type ImageSlideProps = {
10
10
  onLoad?: (image: HTMLImageElement) => void;
11
11
  style?: React.CSSProperties;
12
12
  };
13
- export declare const ImageSlide: ({ slide: image, offset, render, rect, imageFit, onClick, onLoad, style, }: ImageSlideProps) => JSX.Element;
13
+ export declare function ImageSlide({ slide: image, offset, render, rect, imageFit, onClick, onLoad, style }: ImageSlideProps): JSX.Element;
@@ -1,12 +1,12 @@
1
1
  import * as React from "react";
2
- import { clsx, cssClass, hasWindow, makeComposePrefix } from "../utils.js";
2
+ import { clsx, cssClass, hasWindow, isImageFitCover, makeComposePrefix } from "../utils.js";
3
3
  import { useEventCallback } from "../hooks/index.js";
4
4
  import { useEvents, useTimeouts } from "../contexts/index.js";
5
5
  import { ErrorIcon, LoadingIcon } from "./Icons.js";
6
- import { activeSlideStatus, ELEMENT_ICON, IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, } from "../consts.js";
6
+ import { activeSlideStatus, ELEMENT_ICON, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, } from "../consts.js";
7
7
  const slidePrefix = makeComposePrefix("slide");
8
8
  const slideImagePrefix = makeComposePrefix("slide_image");
9
- export const ImageSlide = ({ slide: image, offset, render, rect, imageFit, onClick, onLoad, style, }) => {
9
+ export function ImageSlide({ slide: image, offset, render, rect, imageFit, onClick, onLoad, style }) {
10
10
  var _a, _b, _c, _d, _e, _f, _g;
11
11
  const [status, setStatus] = React.useState(SLIDE_STATUS_LOADING);
12
12
  const { publish } = useEvents();
@@ -45,7 +45,7 @@ export const ImageSlide = ({ slide: image, offset, render, rect, imageFit, onCli
45
45
  const onError = React.useCallback(() => {
46
46
  setStatus(SLIDE_STATUS_ERROR);
47
47
  }, []);
48
- const cover = image.imageFit === IMAGE_FIT_COVER || (image.imageFit !== IMAGE_FIT_CONTAIN && imageFit === IMAGE_FIT_COVER);
48
+ const cover = isImageFitCover(image, imageFit);
49
49
  const nonInfinite = (value, fallback) => (Number.isFinite(value) ? value : fallback);
50
50
  const maxWidth = nonInfinite(Math.max(...((_b = (_a = image.srcSet) === null || _a === void 0 ? void 0 : _a.map((x) => x.width)) !== null && _b !== void 0 ? _b : []).concat(image.width ? [image.width] : [])), ((_c = imageRef.current) === null || _c === void 0 ? void 0 : _c.naturalWidth) || 0);
51
51
  const maxHeight = nonInfinite(Math.max(...((_e = (_d = image.srcSet) === null || _d === void 0 ? void 0 : _d.map((x) => x.height)) !== null && _e !== void 0 ? _e : []).concat(image.height ? [image.height] : [])), ((_f = imageRef.current) === null || _f === void 0 ? void 0 : _f.naturalHeight) || 0);
@@ -68,4 +68,4 @@ export const ImageSlide = ({ slide: image, offset, render, rect, imageFit, onCli
68
68
  ((render === null || render === void 0 ? void 0 : render.iconLoading) ? (render.iconLoading()) : (React.createElement(LoadingIcon, { className: clsx(cssClass(ELEMENT_ICON), cssClass(slidePrefix(SLIDE_STATUS_LOADING))) }))),
69
69
  status === SLIDE_STATUS_ERROR &&
70
70
  ((render === null || render === void 0 ? void 0 : render.iconError) ? (render.iconError()) : (React.createElement(ErrorIcon, { className: clsx(cssClass(ELEMENT_ICON), cssClass(slidePrefix(SLIDE_STATUS_ERROR))) })))))));
71
- };
71
+ }
@@ -13,4 +13,4 @@ export type EventsContextType = {
13
13
  publish: Publish;
14
14
  };
15
15
  export declare const useEvents: () => EventsContextType;
16
- export declare const EventsProvider: React.FC<React.PropsWithChildren>;
16
+ export declare function EventsProvider({ children }: React.PropsWithChildren): JSX.Element;
@@ -2,7 +2,7 @@ import * as React from "react";
2
2
  import { makeUseContext } from "../utils.js";
3
3
  const EventsContext = React.createContext(null);
4
4
  export const useEvents = makeUseContext("useEvents", "EventsContext", EventsContext);
5
- export const EventsProvider = ({ children }) => {
5
+ export function EventsProvider({ children }) {
6
6
  const [subscriptions] = React.useState({});
7
7
  React.useEffect(() => () => {
8
8
  Object.keys(subscriptions).forEach((key) => delete subscriptions[key]);
@@ -26,4 +26,4 @@ export const EventsProvider = ({ children }) => {
26
26
  return { publish, subscribe, unsubscribe };
27
27
  }, [subscriptions]);
28
28
  return React.createElement(EventsContext.Provider, { value: context }, children);
29
- };
29
+ }
@@ -15,9 +15,8 @@ export declare const useLightboxState: () => {
15
15
  state: LightboxState;
16
16
  dispatch: React.Dispatch<LightboxStateAction>;
17
17
  };
18
- type LightboxStateProviderProps = React.PropsWithChildren<{
18
+ export type LightboxStateProviderProps = React.PropsWithChildren<{
19
19
  slidesCount: number;
20
20
  initialIndex: number;
21
21
  }>;
22
- export declare const LightboxStateProvider: React.FC<LightboxStateProviderProps>;
23
- export {};
22
+ export declare function LightboxStateProvider({ initialIndex, slidesCount, children }: LightboxStateProviderProps): JSX.Element;
@@ -14,7 +14,7 @@ const reducer = (slidesCount) => (state, action) => {
14
14
  animationDuration,
15
15
  };
16
16
  };
17
- export const LightboxStateProvider = ({ initialIndex, slidesCount, children, }) => {
17
+ export function LightboxStateProvider({ initialIndex, slidesCount, children }) {
18
18
  const memoizedReducer = React.useMemo(() => reducer(slidesCount), [slidesCount]);
19
19
  const [state, dispatch] = React.useReducer(memoizedReducer, {
20
20
  currentIndex: initialIndex,
@@ -23,4 +23,4 @@ export const LightboxStateProvider = ({ initialIndex, slidesCount, children, })
23
23
  });
24
24
  const context = React.useMemo(() => ({ state, dispatch }), [state, dispatch]);
25
25
  return React.createElement(LightboxStateContext.Provider, { value: context }, children);
26
- };
26
+ }
@@ -4,4 +4,4 @@ export type TimeoutsContextType = {
4
4
  clearTimeout: (id?: number) => void;
5
5
  };
6
6
  export declare const useTimeouts: () => TimeoutsContextType;
7
- export declare const TimeoutsProvider: ({ children }: React.PropsWithChildren<{}>) => JSX.Element;
7
+ export declare function TimeoutsProvider({ children }: React.PropsWithChildren): JSX.Element;
@@ -2,7 +2,7 @@ import * as React from "react";
2
2
  import { isDefined, makeUseContext } from "../utils.js";
3
3
  const TimeoutsContext = React.createContext(null);
4
4
  export const useTimeouts = makeUseContext("useTimeouts", "TimeoutsContext", TimeoutsContext);
5
- export const TimeoutsProvider = ({ children }) => {
5
+ export function TimeoutsProvider({ children }) {
6
6
  const [timeouts] = React.useState([]);
7
7
  React.useEffect(() => () => {
8
8
  timeouts.forEach((tid) => window.clearTimeout(tid));
@@ -29,4 +29,4 @@ export const TimeoutsProvider = ({ children }) => {
29
29
  return { setTimeout, clearTimeout };
30
30
  }, [timeouts]);
31
31
  return React.createElement(TimeoutsContext.Provider, { value: context }, children);
32
- };
32
+ }
@@ -9,4 +9,4 @@ export type ComputeAnimation<T> = (snapshot: T, rect: DOMRect, translate: {
9
9
  easing?: string;
10
10
  onfinish?: () => void;
11
11
  } | undefined;
12
- export declare const useAnimation: <T>(nodeRef: React.RefObject<HTMLElement | null>, computeAnimation: ComputeAnimation<T>) => (currentSnapshot: T | undefined) => void;
12
+ export declare function useAnimation<T>(nodeRef: React.RefObject<HTMLElement | null>, computeAnimation: ComputeAnimation<T>): (currentSnapshot: T | undefined) => void;
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { useLayoutEffect } from "./useLayoutEffect.js";
3
3
  import { useMotionPreference } from "./useMotionPreference.js";
4
- const currentTransformation = (node) => {
4
+ function currentTransformation(node) {
5
5
  let x = 0;
6
6
  let y = 0;
7
7
  let z = 0;
@@ -20,8 +20,8 @@ const currentTransformation = (node) => {
20
20
  }
21
21
  }
22
22
  return { x, y, z };
23
- };
24
- export const useAnimation = (nodeRef, computeAnimation) => {
23
+ }
24
+ export function useAnimation(nodeRef, computeAnimation) {
25
25
  const snapshot = React.useRef();
26
26
  const animation = React.useRef();
27
27
  const reduceMotion = useMotionPreference();
@@ -45,4 +45,4 @@ export const useAnimation = (nodeRef, computeAnimation) => {
45
45
  return (currentSnapshot) => {
46
46
  snapshot.current = currentSnapshot;
47
47
  };
48
- };
48
+ }
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { ContainerRect } from "../../types.js";
3
- export declare const useContainerRect: <T extends HTMLElement = HTMLElement>() => {
3
+ export declare function useContainerRect<T extends HTMLElement = HTMLElement>(): {
4
4
  setContainerRef: (node: T | null) => void;
5
5
  containerRef: React.MutableRefObject<T | null>;
6
6
  containerRect: ContainerRect | undefined;
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- export const useContainerRect = () => {
2
+ export function useContainerRect() {
3
3
  const [containerRect, setContainerRect] = React.useState();
4
4
  const containerRef = React.useRef(null);
5
5
  const observerRef = React.useRef();
@@ -33,4 +33,4 @@ export const useContainerRect = () => {
33
33
  containerRef,
34
34
  containerRect,
35
35
  }), [setContainerRef, containerRef, containerRect]);
36
- };
36
+ }
@@ -1 +1 @@
1
- export declare const useDelay: () => (callback: () => void, delay: number) => void;
1
+ export declare function useDelay(): (callback: () => void, delay: number) => void;
@@ -1,10 +1,10 @@
1
1
  import * as React from "react";
2
2
  import { useTimeouts } from "../contexts/Timeouts.js";
3
- export const useDelay = () => {
3
+ export function useDelay() {
4
4
  const timeoutId = React.useRef();
5
5
  const { setTimeout, clearTimeout } = useTimeouts();
6
6
  return React.useCallback((callback, delay) => {
7
7
  clearTimeout(timeoutId.current);
8
8
  timeoutId.current = setTimeout(callback, delay > 0 ? delay : 0);
9
9
  }, [setTimeout, clearTimeout]);
10
- };
10
+ }
@@ -1 +1 @@
1
- export declare const useEventCallback: <Args extends unknown[], Return>(fn: (...args: Args) => Return) => (...args: Args) => Return;
1
+ export declare function useEventCallback<Args extends unknown[], Return>(fn: (...args: Args) => Return): (...args: Args) => Return;
@@ -1,9 +1,9 @@
1
1
  import * as React from "react";
2
2
  import { useLayoutEffect } from "./useLayoutEffect.js";
3
- export const useEventCallback = (fn) => {
3
+ export function useEventCallback(fn) {
4
4
  const ref = React.useRef(fn);
5
5
  useLayoutEffect(() => {
6
6
  ref.current = fn;
7
7
  });
8
8
  return React.useCallback((...args) => { var _a; return (_a = ref.current) === null || _a === void 0 ? void 0 : _a.call(ref, ...args); }, []);
9
- };
9
+ }
@@ -1,3 +1,3 @@
1
1
  import * as React from "react";
2
- export declare const setRef: <T>(ref: React.MutableRefObject<T | null> | ((instance: T | null) => void) | null | undefined, value: T | null) => void;
3
- export declare const useForkRef: <InstanceA, InstanceB>(refA: React.Ref<InstanceA> | undefined, refB: React.Ref<InstanceB> | undefined) => React.Ref<InstanceA & InstanceB>;
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,15 +1,17 @@
1
1
  import * as React from "react";
2
- export const setRef = (ref, value) => {
2
+ export function setRef(ref, value) {
3
3
  if (typeof ref === "function") {
4
4
  ref(value);
5
5
  }
6
6
  else if (ref) {
7
7
  ref.current = value;
8
8
  }
9
- };
10
- export const useForkRef = (refA, refB) => React.useMemo(() => refA == null && refB == null
11
- ? null
12
- : (refValue) => {
13
- setRef(refA, refValue);
14
- setRef(refB, refValue);
15
- }, [refA, refB]);
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,4 +1,4 @@
1
- export declare const useLoseFocus: (disabled?: boolean) => {
1
+ export declare function useLoseFocus(disabled?: boolean): {
2
2
  onFocus: () => void;
3
3
  onBlur: () => void;
4
4
  };
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { useLayoutEffect } from "./useLayoutEffect.js";
3
3
  import { useController } from "../modules/Controller.js";
4
- export const useLoseFocus = (disabled = false) => {
4
+ export function useLoseFocus(disabled = false) {
5
5
  const focused = React.useRef(disabled);
6
6
  const { transferFocus } = useController();
7
7
  useLayoutEffect(() => {
@@ -16,4 +16,4 @@ export const useLoseFocus = (disabled = false) => {
16
16
  focused.current = false;
17
17
  }, []);
18
18
  return { onFocus, onBlur };
19
- };
19
+ }
@@ -1 +1 @@
1
- export declare const useMotionPreference: () => boolean;
1
+ export declare function useMotionPreference(): boolean;
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- export const useMotionPreference = () => {
2
+ export function useMotionPreference() {
3
3
  const [reduceMotion, setReduceMotion] = React.useState(false);
4
4
  React.useEffect(() => {
5
5
  var _a, _b;
@@ -10,4 +10,4 @@ export const useMotionPreference = () => {
10
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
11
  }, []);
12
12
  return reduceMotion;
13
- };
13
+ }
@@ -1 +1 @@
1
- export declare const useRTL: () => boolean;
1
+ export declare function useRTL(): boolean;
@@ -1,9 +1,9 @@
1
1
  import * as React from "react";
2
2
  import { useLayoutEffect } from "./useLayoutEffect.js";
3
- export const useRTL = () => {
3
+ export function useRTL() {
4
4
  const [isRTL, setIsRTL] = React.useState(false);
5
5
  useLayoutEffect(() => {
6
6
  setIsRTL(window.getComputedStyle(window.document.documentElement).direction === "rtl");
7
7
  }, []);
8
8
  return isRTL;
9
- };
9
+ }
@@ -11,4 +11,4 @@ export type UseSensors<T> = {
11
11
  registerSensors: RegisterSensors<T>;
12
12
  subscribeSensors: SubscribeSensors<T>;
13
13
  };
14
- export declare const useSensors: <T extends Element>() => UseSensors<T>;
14
+ export declare function useSensors<T extends Element>(): UseSensors<T>;
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
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 const useSensors = () => {
3
+ export function useSensors() {
4
4
  const [subscribers] = React.useState({});
5
5
  return React.useMemo(() => {
6
6
  const notifySubscribers = (type, event) => {
@@ -35,4 +35,4 @@ export const useSensors = () => {
35
35
  },
36
36
  };
37
37
  }, [subscribers]);
38
- };
38
+ }
@@ -1 +1 @@
1
- export declare const useThrottle: (callback: (...args: any[]) => void, delay: number) => (...args: any[]) => void;
1
+ export declare function useThrottle(callback: (...args: any[]) => void, delay: number): (...args: any[]) => void;
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { useDelay } from "./useDelay.js";
3
3
  import { useEventCallback } from "./useEventCallback.js";
4
- export const useThrottle = (callback, delay) => {
4
+ export function useThrottle(callback, delay) {
5
5
  const lastCallbackTime = React.useRef(0);
6
6
  const delayCallback = useDelay();
7
7
  const executeCallback = useEventCallback((...args) => {
@@ -13,4 +13,4 @@ export const useThrottle = (callback, delay) => {
13
13
  executeCallback(args);
14
14
  }, delay - (Date.now() - lastCallbackTime.current));
15
15
  }, [delay, executeCallback, delayCallback]);
16
- };
16
+ }
@@ -1,3 +1,4 @@
1
- import { Component } from "../../types.js";
2
- export declare const Carousel: Component;
1
+ /// <reference types="react" />
2
+ import { ComponentProps } from "../../types.js";
3
+ export declare function Carousel({ slides, carousel: { finite, preload, padding, spacing } }: ComponentProps): JSX.Element;
3
4
  export declare const CarouselModule: import("../../types.js").Module;
@@ -1,20 +1,23 @@
1
1
  import * as React from "react";
2
2
  import { createModule } from "../config.js";
3
- import { useContainerRect } from "../hooks/index.js";
4
3
  import { clsx, composePrefix, cssClass, cssVar, isImageSlide, parseLengthPercentage } from "../utils.js";
5
4
  import { ImageSlide } from "../components/index.js";
6
5
  import { useController } from "./Controller.js";
7
6
  import { useEvents } from "../contexts/Events.js";
8
7
  import { useLightboxState } from "../contexts/LightboxState.js";
9
8
  import { CLASS_FLEX_CENTER, CLASS_FULLSIZE, MODULE_CAROUSEL, YARL_EVENT_BACKDROP_CLICK } from "../consts.js";
10
- const cssPrefix = (value) => composePrefix(MODULE_CAROUSEL, value);
11
- const cssSlidePrefix = (value) => composePrefix("slide", value);
12
- const CarouselSlide = ({ slide, offset }) => {
13
- const { setContainerRef, containerRect, containerRef } = useContainerRect();
9
+ function cssPrefix(value) {
10
+ return composePrefix(MODULE_CAROUSEL, value);
11
+ }
12
+ function cssSlidePrefix(value) {
13
+ return composePrefix("slide", value);
14
+ }
15
+ function CarouselSlide({ slide, offset, rect }) {
16
+ const containerRef = React.useRef(null);
14
17
  const { publish } = useEvents();
15
18
  const { currentIndex } = useLightboxState().state;
16
19
  const { render, carousel: { imageFit }, on: { click: onClick }, } = useController().getLightboxProps();
17
- const renderSlide = (rect) => {
20
+ const renderSlide = () => {
18
21
  var _a, _b, _c, _d;
19
22
  let rendered = (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, slide, offset, rect);
20
23
  if (!rendered && isImageSlide(slide)) {
@@ -36,24 +39,31 @@ const CarouselSlide = ({ slide, offset }) => {
36
39
  publish(YARL_EVENT_BACKDROP_CLICK);
37
40
  }
38
41
  };
39
- return (React.createElement("div", { ref: setContainerRef, className: clsx(cssClass(cssSlidePrefix()), offset === 0 && cssClass(cssSlidePrefix("current")), cssClass(CLASS_FLEX_CENTER)), onClick: handleBackdropClick }, containerRect && renderSlide(containerRect)));
40
- };
41
- const Placeholder = () => React.createElement("div", { className: cssClass("slide") });
42
- export const Carousel = ({ slides, carousel: { finite, preload, padding, spacing } }) => {
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({ slides, carousel: { finite, preload, padding, spacing } }) {
43
48
  const { currentIndex, globalIndex } = useLightboxState().state;
44
- const { setCarouselRef } = useController();
49
+ const { setCarouselRef, containerRect } = useController();
45
50
  const spacingValue = parseLengthPercentage(spacing);
46
51
  const paddingValue = parseLengthPercentage(padding);
52
+ const paddingPixels = paddingValue.percent !== undefined ? (containerRect.width / 100) * paddingValue.percent : paddingValue.pixel;
53
+ const rect = {
54
+ width: Math.max(containerRect.width - 2 * paddingPixels, 0),
55
+ height: Math.max(containerRect.height - 2 * paddingPixels, 0),
56
+ };
47
57
  const items = [];
48
58
  if ((slides === null || slides === void 0 ? void 0 : slides.length) > 0) {
49
59
  for (let i = currentIndex - preload; i < currentIndex; i += 1) {
50
60
  const key = globalIndex + i - currentIndex;
51
- 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 })));
61
+ items.push(!finite || i >= 0 ? (React.createElement(CarouselSlide, { key: key, slide: slides[(i + preload * slides.length) % slides.length], rect: rect, offset: i - currentIndex })) : (React.createElement(Placeholder, { key: key })));
52
62
  }
53
- items.push(React.createElement(CarouselSlide, { key: globalIndex, slide: slides[currentIndex], offset: 0 }));
63
+ items.push(React.createElement(CarouselSlide, { key: globalIndex, slide: slides[currentIndex], rect: rect, offset: 0 }));
54
64
  for (let i = currentIndex + 1; i <= currentIndex + preload; i += 1) {
55
65
  const key = globalIndex + i - currentIndex;
56
- 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 })));
66
+ items.push(!finite || i <= slides.length - 1 ? (React.createElement(CarouselSlide, { key: key, slide: slides[i % slides.length], rect: rect, offset: i - currentIndex })) : (React.createElement(Placeholder, { key: key })));
57
67
  }
58
68
  }
59
69
  return (React.createElement("div", { ref: setCarouselRef, className: clsx(cssClass(cssPrefix()), items.length > 0 && cssClass(cssPrefix("with_slides"))), style: {
@@ -63,5 +73,5 @@ export const Carousel = ({ slides, carousel: { finite, preload, padding, spacing
63
73
  [`${cssVar(cssPrefix("padding_px"))}`]: paddingValue.pixel || 0,
64
74
  [`${cssVar(cssPrefix("padding_percent"))}`]: paddingValue.percent || 0,
65
75
  } }, items));
66
- };
76
+ }
67
77
  export const CarouselModule = createModule(MODULE_CAROUSEL, Carousel);
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { Component, ComponentProps, ContainerRect } from "../../types.js";
2
+ import { ComponentProps, ContainerRect } from "../../types.js";
3
3
  import { SubscribeSensors } from "../hooks/index.js";
4
4
  import { LightboxStateAction } from "../contexts/index.js";
5
5
  import { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, YARL_EVENT_BACKDROP_CLICK } from "../consts.js";
@@ -24,5 +24,5 @@ export type ControllerContextType = {
24
24
  setCarouselRef: React.Ref<HTMLDivElement>;
25
25
  };
26
26
  export declare const useController: () => ControllerContextType;
27
- export declare const Controller: Component;
27
+ export declare function Controller({ children, ...props }: ComponentProps): JSX.Element;
28
28
  export declare const ControllerModule: import("../../types.js").Module;
@@ -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);
@@ -176,5 +176,5 @@ export const Controller = ({ children, ...props }) => {
176
176
  : null),
177
177
  ...styles.container,
178
178
  }, ...(controller.aria ? { role: "presentation", "aria-live": "polite" } : null), tabIndex: -1, ...registerSensors }, containerRect && React.createElement(ControllerContext.Provider, { value: context }, children)));
179
- };
179
+ }
180
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;