yet-another-react-lightbox 2.6.2 → 3.0.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 (129) hide show
  1. package/dist/Lightbox.d.ts +1 -1
  2. package/dist/Lightbox.js +17 -13
  3. package/dist/core/components/IconButton.js +2 -2
  4. package/dist/core/components/ImageSlide.js +0 -3
  5. package/dist/core/config.d.ts +3 -3
  6. package/dist/core/config.js +18 -13
  7. package/dist/core/consts.d.ts +2 -4
  8. package/dist/core/consts.js +2 -4
  9. package/dist/core/contexts/Events.d.ts +3 -2
  10. package/dist/core/contexts/Events.js +3 -3
  11. package/dist/core/contexts/LightboxProps.d.ts +6 -0
  12. package/dist/core/contexts/LightboxProps.js +7 -0
  13. package/dist/core/contexts/LightboxState.d.ts +15 -15
  14. package/dist/core/contexts/LightboxState.js +33 -20
  15. package/dist/core/contexts/Timeouts.d.ts +1 -0
  16. package/dist/core/contexts/Timeouts.js +3 -3
  17. package/dist/core/contexts/index.d.ts +1 -0
  18. package/dist/core/contexts/index.js +1 -0
  19. package/dist/core/hooks/useAnimation.d.ts +4 -1
  20. package/dist/core/hooks/useAnimation.js +12 -3
  21. package/dist/core/hooks/useLoseFocus.js +3 -3
  22. package/dist/core/modules/Carousel.d.ts +1 -1
  23. package/dist/core/modules/Carousel.js +19 -24
  24. package/dist/core/modules/Controller.d.ts +15 -16
  25. package/dist/core/modules/Controller.js +68 -34
  26. package/dist/core/modules/Navigation.d.ts +4 -5
  27. package/dist/core/modules/Navigation.js +15 -12
  28. package/dist/core/modules/Portal.js +5 -4
  29. package/dist/core/modules/Root.d.ts +4 -0
  30. package/dist/core/modules/Root.js +7 -0
  31. package/dist/core/modules/Toolbar.d.ts +0 -6
  32. package/dist/core/modules/Toolbar.js +6 -8
  33. package/dist/core/modules/index.d.ts +1 -1
  34. package/dist/core/modules/index.js +1 -1
  35. package/dist/core/utils.d.ts +7 -10
  36. package/dist/core/utils.js +14 -14
  37. package/dist/plugins/captions/Captions.d.ts +2 -6
  38. package/dist/plugins/captions/Captions.js +17 -20
  39. package/dist/plugins/captions/Description.d.ts +2 -2
  40. package/dist/plugins/captions/Description.js +5 -3
  41. package/dist/plugins/captions/Title.js +2 -3
  42. package/dist/plugins/captions/captions.css +1 -0
  43. package/dist/plugins/captions/index.d.ts +2 -2
  44. package/dist/plugins/captions/props.d.ts +9 -0
  45. package/dist/plugins/captions/props.js +8 -0
  46. package/dist/plugins/captions/utils.d.ts +1 -1
  47. package/dist/plugins/captions/utils.js +1 -3
  48. package/dist/plugins/fullscreen/Fullscreen.d.ts +2 -2
  49. package/dist/plugins/fullscreen/Fullscreen.js +5 -3
  50. package/dist/plugins/fullscreen/FullscreenButton.js +8 -5
  51. package/dist/plugins/fullscreen/FullscreenContext.d.ts +5 -9
  52. package/dist/plugins/fullscreen/FullscreenContext.js +16 -26
  53. package/dist/plugins/fullscreen/index.d.ts +21 -10
  54. package/dist/plugins/fullscreen/props.d.ts +10 -0
  55. package/dist/plugins/fullscreen/props.js +8 -0
  56. package/dist/plugins/inline/Inline.d.ts +2 -2
  57. package/dist/plugins/inline/Inline.js +4 -7
  58. package/dist/plugins/inline/InlineContainer.d.ts +4 -0
  59. package/dist/plugins/inline/InlineContainer.js +5 -0
  60. package/dist/plugins/inline/index.d.ts +1 -1
  61. package/dist/plugins/slideshow/Slideshow.d.ts +2 -6
  62. package/dist/plugins/slideshow/Slideshow.js +7 -10
  63. package/dist/plugins/slideshow/SlideshowButton.js +7 -5
  64. package/dist/plugins/slideshow/SlideshowContext.d.ts +5 -9
  65. package/dist/plugins/slideshow/SlideshowContext.js +21 -12
  66. package/dist/plugins/slideshow/index.d.ts +16 -11
  67. package/dist/plugins/slideshow/props.d.ts +12 -0
  68. package/dist/plugins/slideshow/props.js +9 -0
  69. package/dist/plugins/thumbnails/Thumbnail.d.ts +3 -7
  70. package/dist/plugins/thumbnails/Thumbnail.js +7 -3
  71. package/dist/plugins/thumbnails/Thumbnails.d.ts +2 -13
  72. package/dist/plugins/thumbnails/Thumbnails.js +6 -19
  73. package/dist/plugins/thumbnails/ThumbnailsContainer.d.ts +1 -1
  74. package/dist/plugins/thumbnails/ThumbnailsContainer.js +10 -10
  75. package/dist/plugins/thumbnails/ThumbnailsTrack.d.ts +4 -6
  76. package/dist/plugins/thumbnails/ThumbnailsTrack.js +16 -14
  77. package/dist/plugins/thumbnails/index.d.ts +5 -5
  78. package/dist/plugins/thumbnails/props.d.ts +34 -0
  79. package/dist/plugins/thumbnails/props.js +20 -0
  80. package/dist/plugins/video/Video.d.ts +2 -6
  81. package/dist/plugins/video/Video.js +11 -11
  82. package/dist/plugins/video/VideoSlide.d.ts +1 -1
  83. package/dist/plugins/video/VideoSlide.js +3 -3
  84. package/dist/plugins/video/index.d.ts +39 -42
  85. package/dist/plugins/video/props.d.ts +29 -0
  86. package/dist/plugins/video/props.js +13 -0
  87. package/dist/plugins/zoom/ResponsiveImage.js +23 -15
  88. package/dist/plugins/zoom/Zoom.d.ts +0 -11
  89. package/dist/plugins/zoom/Zoom.js +11 -33
  90. package/dist/plugins/zoom/ZoomButton.d.ts +6 -5
  91. package/dist/plugins/zoom/ZoomButton.js +11 -33
  92. package/dist/plugins/zoom/ZoomButtonsGroup.d.ts +1 -4
  93. package/dist/plugins/zoom/ZoomButtonsGroup.js +6 -7
  94. package/dist/plugins/zoom/ZoomController.d.ts +12 -0
  95. package/dist/plugins/zoom/ZoomController.js +17 -0
  96. package/dist/plugins/zoom/ZoomToolbarControl.d.ts +2 -0
  97. package/dist/plugins/zoom/ZoomToolbarControl.js +12 -0
  98. package/dist/plugins/zoom/ZoomWrapper.d.ts +5 -0
  99. package/dist/plugins/zoom/ZoomWrapper.js +36 -0
  100. package/dist/plugins/zoom/hooks/index.d.ts +6 -0
  101. package/dist/plugins/zoom/hooks/index.js +6 -0
  102. package/dist/plugins/zoom/hooks/useZoomAnimation.d.ts +2 -0
  103. package/dist/plugins/zoom/hooks/useZoomAnimation.js +39 -0
  104. package/dist/plugins/zoom/hooks/useZoomCallback.d.ts +1 -0
  105. package/dist/plugins/zoom/hooks/useZoomCallback.js +12 -0
  106. package/dist/plugins/zoom/hooks/useZoomImageRect.d.ts +5 -0
  107. package/dist/plugins/zoom/hooks/useZoomImageRect.js +41 -0
  108. package/dist/plugins/zoom/hooks/useZoomProps.d.ts +13 -0
  109. package/dist/plugins/zoom/hooks/useZoomProps.js +6 -0
  110. package/dist/plugins/zoom/hooks/useZoomSensors.d.ts +3 -0
  111. package/dist/plugins/zoom/hooks/useZoomSensors.js +154 -0
  112. package/dist/plugins/zoom/hooks/useZoomState.d.ts +12 -0
  113. package/dist/plugins/zoom/hooks/useZoomState.js +63 -0
  114. package/dist/plugins/zoom/index.d.ts +37 -24
  115. package/dist/plugins/zoom/index.js +0 -2
  116. package/dist/plugins/zoom/props.d.ts +25 -0
  117. package/dist/plugins/zoom/props.js +15 -0
  118. package/dist/props.d.ts +0 -4
  119. package/dist/props.js +10 -5
  120. package/dist/types.d.ts +173 -117
  121. package/package.json +41 -11
  122. package/dist/core/modules/Core.d.ts +0 -4
  123. package/dist/core/modules/Core.js +0 -10
  124. package/dist/plugins/captions/CaptionsContext.d.ts +0 -7
  125. package/dist/plugins/captions/CaptionsContext.js +0 -11
  126. package/dist/plugins/zoom/ZoomContainer.d.ts +0 -9
  127. package/dist/plugins/zoom/ZoomContainer.js +0 -316
  128. package/dist/plugins/zoom/ZoomContext.d.ts +0 -11
  129. package/dist/plugins/zoom/ZoomContext.js +0 -20
@@ -1,13 +1,16 @@
1
1
  import * as React from "react";
2
- import { createIcon, IconButton, label, useController } from "../../core/index.js";
2
+ import { createIcon, IconButton, label, useLightboxProps } from "../../core/index.js";
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
6
  export function FullscreenButton() {
7
7
  var _a;
8
- const { labels, render } = useController().getLightboxProps();
9
- const { fullscreen, fullscreenEnabled, toggleFullscreen } = useFullscreen();
10
- if (!fullscreenEnabled)
8
+ const { fullscreen, disabled, enter, exit } = useFullscreen();
9
+ const { labels, render } = useLightboxProps();
10
+ if (disabled)
11
11
  return null;
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 }));
12
+ if (render.buttonFullscreen) {
13
+ return React.createElement(React.Fragment, null, (_a = render.buttonFullscreen) === null || _a === void 0 ? void 0 : _a.call(render, { fullscreen, disabled, enter, exit }));
14
+ }
15
+ return (React.createElement(IconButton, { disabled: disabled, label: fullscreen ? label(labels, "Exit Fullscreen") : label(labels, "Enter Fullscreen"), icon: fullscreen ? ExitFullscreenIcon : EnterFullscreenIcon, renderIcon: fullscreen ? render.iconExitFullscreen : render.iconEnterFullscreen, onClick: () => (fullscreen ? exit : enter)() }));
13
16
  }
@@ -1,9 +1,5 @@
1
- /// <reference types="react" />
2
- import { ComponentProps } from "../../types.js";
3
- export type FullscreenContextType = {
4
- fullscreen: boolean;
5
- fullscreenEnabled?: boolean;
6
- toggleFullscreen: () => void;
7
- };
8
- export declare const useFullscreen: () => FullscreenContextType;
9
- export declare function FullscreenContextProvider({ fullscreen: auto, children }: ComponentProps): JSX.Element;
1
+ import * as React from "react";
2
+ import { ComponentProps, FullscreenRef } from "../../types.js";
3
+ export declare const FullscreenContext: React.Context<FullscreenRef | null>;
4
+ export declare const useFullscreen: () => FullscreenRef;
5
+ export declare function FullscreenContextProvider({ fullscreen: fullscreenProps, children }: ComponentProps): JSX.Element;
@@ -1,20 +1,22 @@
1
1
  import * as React from "react";
2
2
  import { CLASS_FULLSIZE, clsx, cssClass, makeUseContext, PLUGIN_FULLSCREEN, useEventCallback, useLayoutEffect, } from "../../core/index.js";
3
- const FullscreenContext = React.createContext(null);
3
+ import { resolveFullscreenProps } from "./props.js";
4
+ export const FullscreenContext = React.createContext(null);
4
5
  export const useFullscreen = makeUseContext("useFullscreen", "FullscreenContext", FullscreenContext);
5
- export function FullscreenContextProvider({ fullscreen: auto, children }) {
6
+ export function FullscreenContextProvider({ fullscreen: fullscreenProps, children }) {
7
+ const { auto, ref } = resolveFullscreenProps(fullscreenProps);
6
8
  const containerRef = React.useRef(null);
7
9
  const [fullscreen, setFullscreen] = React.useState(false);
8
- const [fullscreenEnabled, setFullscreenEnabled] = React.useState();
10
+ const [disabled, setDisabled] = React.useState();
9
11
  useLayoutEffect(() => {
10
12
  var _a, _b, _c, _d;
11
- setFullscreenEnabled((_d = (_c = (_b = (_a = document.fullscreenEnabled) !== null && _a !== void 0 ? _a : document.webkitFullscreenEnabled) !== null && _b !== void 0 ? _b : document.mozFullScreenEnabled) !== null && _c !== void 0 ? _c : document.msFullscreenEnabled) !== null && _d !== void 0 ? _d : false);
13
+ setDisabled(!((_d = (_c = (_b = (_a = document.fullscreenEnabled) !== null && _a !== void 0 ? _a : document.webkitFullscreenEnabled) !== null && _b !== void 0 ? _b : document.mozFullScreenEnabled) !== null && _c !== void 0 ? _c : document.msFullscreenEnabled) !== null && _d !== void 0 ? _d : false));
12
14
  }, []);
13
15
  const getFullscreenElement = React.useCallback(() => {
14
16
  var _a, _b, _c;
15
17
  return (_c = (_b = (_a = document.fullscreenElement) !== null && _a !== void 0 ? _a : document.webkitFullscreenElement) !== null && _b !== void 0 ? _b : document.mozFullScreenElement) !== null && _c !== void 0 ? _c : document.msFullscreenElement;
16
18
  }, []);
17
- const requestFullscreen = React.useCallback(() => {
19
+ const enter = React.useCallback(() => {
18
20
  const container = containerRef.current;
19
21
  if (container) {
20
22
  try {
@@ -35,7 +37,7 @@ export function FullscreenContextProvider({ fullscreen: auto, children }) {
35
37
  }
36
38
  }
37
39
  }, []);
38
- const exitFullscreen = React.useCallback(() => {
40
+ const exit = React.useCallback(() => {
39
41
  if (getFullscreenElement()) {
40
42
  try {
41
43
  if (document.exitFullscreen) {
@@ -55,14 +57,6 @@ export function FullscreenContextProvider({ fullscreen: auto, children }) {
55
57
  }
56
58
  }
57
59
  }, [getFullscreenElement]);
58
- const toggleFullscreen = React.useCallback(() => {
59
- if (fullscreen) {
60
- exitFullscreen();
61
- }
62
- else {
63
- requestFullscreen();
64
- }
65
- }, [fullscreen, requestFullscreen, exitFullscreen]);
66
60
  const fullscreenChangeListener = React.useCallback(() => {
67
61
  if (getFullscreenElement() === containerRef.current) {
68
62
  setFullscreen(true);
@@ -82,22 +76,18 @@ export function FullscreenContextProvider({ fullscreen: auto, children }) {
82
76
  });
83
77
  };
84
78
  }, [fullscreenChangeListener]);
85
- const handleAutoFullscreen = useEventCallback(() => {
86
- if (auto) {
87
- requestFullscreen();
88
- }
89
- });
79
+ const handleAutoFullscreen = useEventCallback(() => { var _a; return (_a = (auto ? enter : null)) === null || _a === void 0 ? void 0 : _a(); });
90
80
  React.useEffect(() => {
91
81
  handleAutoFullscreen();
92
- return () => {
93
- exitFullscreen();
94
- };
95
- }, [handleAutoFullscreen, exitFullscreen]);
82
+ return () => exit();
83
+ }, [handleAutoFullscreen, exit]);
96
84
  const context = React.useMemo(() => ({
97
85
  fullscreen,
98
- fullscreenEnabled,
99
- toggleFullscreen,
100
- }), [fullscreen, fullscreenEnabled, toggleFullscreen]);
86
+ disabled,
87
+ enter,
88
+ exit,
89
+ }), [fullscreen, disabled, enter, exit]);
90
+ React.useImperativeHandle(ref, () => context, [context]);
101
91
  return (React.createElement("div", { ref: containerRef, className: clsx(cssClass(PLUGIN_FULLSCREEN), cssClass(CLASS_FULLSIZE)) },
102
92
  React.createElement(FullscreenContext.Provider, { value: context }, children)));
103
93
  }
@@ -1,23 +1,34 @@
1
+ import * as React from "react";
1
2
  import { Fullscreen } from "./Fullscreen.js";
2
- declare module "../../types" {
3
+ declare module "../../types.js" {
3
4
  interface LightboxProps {
4
- /** if `true`, enter fullscreen mode automatically when the lightbox opens */
5
- fullscreen?: boolean;
5
+ /** Fullscreen plugin settings */
6
+ fullscreen?: {
7
+ /** Fullscreen plugin ref */
8
+ ref?: React.ForwardedRef<FullscreenRef>;
9
+ /** if `true`, enter fullscreen mode automatically when the lightbox opens */
10
+ auto?: boolean;
11
+ };
6
12
  }
7
- /** `render.buttonFullscreen` render function props */
8
- type RenderFullscreenButtonProps = {
9
- fullscreen: boolean;
10
- fullscreenEnabled: boolean | undefined;
11
- toggleFullscreen: () => void;
12
- };
13
13
  interface Render {
14
14
  /** render custom Enter/Exit Fullscreen button */
15
- buttonFullscreen?: RenderFunction<RenderFullscreenButtonProps>;
15
+ buttonFullscreen?: RenderFunction<FullscreenRef>;
16
16
  /** render custom Enter Fullscreen icon */
17
17
  iconEnterFullscreen?: RenderFunction;
18
18
  /** render custom Exit Fullscreen icon */
19
19
  iconExitFullscreen?: RenderFunction;
20
20
  }
21
+ /** Fullscreen plugin ref */
22
+ interface FullscreenRef {
23
+ /** current fullscreen status */
24
+ fullscreen: boolean;
25
+ /** if `true`, fullscreen features are not available */
26
+ disabled: boolean | undefined;
27
+ /** enter fullscreen mode */
28
+ enter: Callback;
29
+ /** exit fullscreen mode */
30
+ exit: Callback;
31
+ }
21
32
  }
22
33
  declare global {
23
34
  interface Document {
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { LightboxProps } from "../../types.js";
3
+ export declare const defaultFullscreenProps: {
4
+ auto: boolean;
5
+ ref: null;
6
+ };
7
+ export declare const resolveFullscreenProps: (fullscreen: LightboxProps["fullscreen"]) => {
8
+ ref: import("react").ForwardedRef<import("../../types.js").FullscreenRef>;
9
+ auto: boolean;
10
+ };
@@ -0,0 +1,8 @@
1
+ export const defaultFullscreenProps = {
2
+ auto: false,
3
+ ref: null,
4
+ };
5
+ export const resolveFullscreenProps = (fullscreen) => ({
6
+ ...defaultFullscreenProps,
7
+ ...fullscreen,
8
+ });
@@ -1,3 +1,3 @@
1
- import { Plugin } from "../../types.js";
1
+ import { PluginProps } from "../../types.js";
2
2
  /** Inline plugin */
3
- export declare const Inline: Plugin;
3
+ export declare function Inline({ augment, replace, remove }: PluginProps): void;
@@ -1,9 +1,6 @@
1
- import * as React from "react";
2
- import { ACTION_CLOSE, clsx, createModule, cssClass, MODULE_NO_SCROLL, MODULE_PORTAL, PLUGIN_INLINE, } from "../../core/index.js";
3
- function InlineContainer({ inline: { className, ...rest } = {}, children }) {
4
- return (React.createElement("div", { className: clsx(cssClass("root"), cssClass("relative"), className), ...rest }, children));
5
- }
6
- export const Inline = ({ augment, replace, remove }) => {
1
+ import { ACTION_CLOSE, createModule, MODULE_NO_SCROLL, MODULE_PORTAL, PLUGIN_INLINE } from "../../core/index.js";
2
+ import { InlineContainer } from "./InlineContainer.js";
3
+ export function Inline({ augment, replace, remove }) {
7
4
  augment(({ toolbar: { buttons, ...restToolbar }, open, close, controller: { focus, aria, touchAction, ...restController }, className, ...restProps }) => ({
8
5
  open: true,
9
6
  close: () => { },
@@ -18,4 +15,4 @@ export const Inline = ({ augment, replace, remove }) => {
18
15
  }));
19
16
  remove(MODULE_NO_SCROLL);
20
17
  replace(MODULE_PORTAL, createModule(PLUGIN_INLINE, InlineContainer));
21
- };
18
+ }
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { ComponentProps } from "../../types.js";
3
+ /** Inline plugin container */
4
+ export declare function InlineContainer({ inline: { className, ...rest }, children }: ComponentProps): JSX.Element;
@@ -0,0 +1,5 @@
1
+ import * as React from "react";
2
+ import { clsx, cssClass } from "../../core/index.js";
3
+ export function InlineContainer({ inline: { className, ...rest } = {}, children }) {
4
+ return (React.createElement("div", { className: clsx(cssClass("root"), cssClass("relative"), className), ...rest }, children));
5
+ }
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { Inline } from "./Inline.js";
3
- declare module "../../types" {
3
+ declare module "../../types.js" {
4
4
  interface LightboxProps {
5
5
  /** HTML div element attributes to be passed to the Inline plugin container */
6
6
  inline?: React.HTMLAttributes<HTMLDivElement>;
@@ -1,7 +1,3 @@
1
- import { Plugin } from "../../types.js";
2
- export declare const defaultSlideshowProps: {
3
- autoplay: boolean;
4
- delay: number;
5
- };
1
+ import { PluginProps } from "../../types.js";
6
2
  /** Slideshow plugin */
7
- export declare const Slideshow: Plugin;
3
+ export declare function Slideshow({ augment, addModule }: PluginProps): void;
@@ -1,16 +1,13 @@
1
1
  import * as React from "react";
2
- import { createModule, MODULE_CONTROLLER, PLUGIN_SLIDESHOW } from "../../core/index.js";
2
+ import { createModule, PLUGIN_SLIDESHOW } from "../../core/index.js";
3
+ import { resolveSlideshowProps } from "./props.js";
3
4
  import { SlideshowContextProvider } from "./SlideshowContext.js";
4
5
  import { SlideshowButton } from "./SlideshowButton.js";
5
- export const defaultSlideshowProps = {
6
- autoplay: false,
7
- delay: 3000,
8
- };
9
- export const Slideshow = ({ augment, append }) => {
10
- augment(({ slideshow: slideshowProps, toolbar: { buttons, ...restToolbar }, ...restProps }) => ({
6
+ export function Slideshow({ augment, addModule }) {
7
+ augment(({ slideshow, toolbar: { buttons, ...restToolbar }, ...restProps }) => ({
11
8
  toolbar: { buttons: [React.createElement(SlideshowButton, { key: PLUGIN_SLIDESHOW }), ...buttons], ...restToolbar },
12
- slideshow: { ...defaultSlideshowProps, ...slideshowProps },
9
+ slideshow: resolveSlideshowProps(slideshow),
13
10
  ...restProps,
14
11
  }));
15
- append(MODULE_CONTROLLER, createModule(PLUGIN_SLIDESHOW, SlideshowContextProvider));
16
- };
12
+ addModule(createModule(PLUGIN_SLIDESHOW, SlideshowContextProvider));
13
+ }
@@ -1,12 +1,14 @@
1
1
  import * as React from "react";
2
- import { createIcon, IconButton, label, useController, useLoseFocus } from "../../core/index.js";
2
+ import { createIcon, IconButton, label, useLightboxProps, useLoseFocus } from "../../core/index.js";
3
3
  import { useSlideshow } from "./SlideshowContext.js";
4
4
  const PlayIcon = createIcon("Play", React.createElement("path", { d: "M8 5v14l11-7z" }));
5
5
  const PauseIcon = createIcon("Pause", React.createElement("path", { d: "M6 19h4V5H6v14zm8-14v14h4V5h-4z" }));
6
6
  export function SlideshowButton() {
7
- const { playing, disabled, togglePlaying } = useSlideshow();
8
- const { getLightboxProps } = useController();
9
- const { render, labels } = getLightboxProps();
7
+ const { playing, disabled, play, pause } = useSlideshow();
8
+ const { render, labels } = useLightboxProps();
10
9
  const focusListeners = useLoseFocus(disabled);
11
- return render.buttonSlideshow ? (React.createElement(React.Fragment, null, render.buttonSlideshow({ playing, togglePlaying, disabled }))) : (React.createElement(IconButton, { label: playing ? label(labels, "Pause") : label(labels, "Play"), icon: playing ? PauseIcon : PlayIcon, renderIcon: playing ? render.iconSlideshowPause : render.iconSlideshowPlay, onClick: togglePlaying, disabled: disabled, ...focusListeners }));
10
+ if (render.buttonSlideshow) {
11
+ return React.createElement(React.Fragment, null, render.buttonSlideshow({ playing, disabled, play, pause }));
12
+ }
13
+ return (React.createElement(IconButton, { label: playing ? label(labels, "Pause") : label(labels, "Play"), icon: playing ? PauseIcon : PlayIcon, renderIcon: playing ? render.iconSlideshowPause : render.iconSlideshowPlay, onClick: () => (playing ? pause : play)(), disabled: disabled, ...focusListeners }));
12
14
  }
@@ -1,9 +1,5 @@
1
- /// <reference types="react" />
2
- import { ComponentProps } from "../../types.js";
3
- export type SlideshowContextType = {
4
- playing: boolean;
5
- disabled: boolean;
6
- togglePlaying: () => void;
7
- };
8
- export declare const useSlideshow: () => SlideshowContextType;
9
- export declare function SlideshowContextProvider({ slides, slideshow, carousel: { finite }, children }: ComponentProps): JSX.Element;
1
+ import * as React from "react";
2
+ import { ComponentProps, SlideshowRef } from "../../types.js";
3
+ export declare const SlideshowContext: React.Context<SlideshowRef | null>;
4
+ export declare const useSlideshow: () => SlideshowRef;
5
+ export declare function SlideshowContextProvider({ slideshow, carousel: { finite }, children }: ComponentProps): JSX.Element;
@@ -1,20 +1,28 @@
1
1
  import * as React from "react";
2
- import { ACTION_NEXT, ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, cleanup, makeUseContext, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLAYING, useEventCallback, useEvents, useLightboxState, useTimeouts, } from "../../core/index.js";
3
- import { defaultSlideshowProps } from "./Slideshow.js";
4
- const SlideshowContext = React.createContext(null);
2
+ import { ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, cleanup, makeUseContext, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLAYING, useController, useEventCallback, useEvents, useLightboxState, useTimeouts, } from "../../core/index.js";
3
+ import { resolveSlideshowProps } from "./props.js";
4
+ export const SlideshowContext = React.createContext(null);
5
5
  export const useSlideshow = makeUseContext("useSlideshow", "SlideshowContext", SlideshowContext);
6
- export function SlideshowContextProvider({ slides, slideshow, carousel: { finite }, children }) {
7
- const { autoplay, delay } = { ...defaultSlideshowProps, ...slideshow };
6
+ export function SlideshowContextProvider({ slideshow, carousel: { finite }, children }) {
7
+ const { autoplay, delay, ref } = resolveSlideshowProps(slideshow);
8
8
  const [playing, setPlaying] = React.useState(autoplay);
9
9
  const scheduler = React.useRef();
10
10
  const slideStatus = React.useRef();
11
- const { currentIndex } = useLightboxState().state;
11
+ const { slides, currentIndex } = useLightboxState().state;
12
12
  const { setTimeout, clearTimeout } = useTimeouts();
13
- const { publish, subscribe } = useEvents();
13
+ const { subscribe } = useEvents();
14
+ const { next } = useController();
14
15
  const disabled = slides.length === 0 || (finite && currentIndex === slides.length - 1);
15
- const togglePlaying = React.useCallback(() => {
16
- setPlaying((prev) => !prev);
17
- }, []);
16
+ const play = React.useCallback(() => {
17
+ if (!playing && !disabled) {
18
+ setPlaying(true);
19
+ }
20
+ }, [playing, disabled]);
21
+ const pause = React.useCallback(() => {
22
+ if (playing) {
23
+ setPlaying(false);
24
+ }
25
+ }, [playing]);
18
26
  const cancelScheduler = React.useCallback(() => {
19
27
  clearTimeout(scheduler.current);
20
28
  scheduler.current = undefined;
@@ -30,7 +38,7 @@ export function SlideshowContextProvider({ slides, slideshow, carousel: { finite
30
38
  scheduler.current = setTimeout(() => {
31
39
  if (playing) {
32
40
  slideStatus.current = undefined;
33
- publish(ACTION_NEXT);
41
+ next();
34
42
  }
35
43
  }, delay);
36
44
  });
@@ -53,6 +61,7 @@ export function SlideshowContextProvider({ slides, slideshow, carousel: { finite
53
61
  slideStatus.current = SLIDE_STATUS_COMPLETE;
54
62
  scheduleNextSlide();
55
63
  })), [subscribe, cancelScheduler, scheduleNextSlide]);
56
- const context = React.useMemo(() => ({ playing, disabled, togglePlaying }), [playing, disabled, togglePlaying]);
64
+ const context = React.useMemo(() => ({ playing, disabled, play, pause }), [playing, disabled, play, pause]);
65
+ React.useImperativeHandle(ref, () => context, [context]);
57
66
  return React.createElement(SlideshowContext.Provider, { value: context }, children);
58
67
  }
@@ -1,30 +1,35 @@
1
+ /// <reference types="react" />
1
2
  import { Slideshow } from "./Slideshow.js";
2
- declare module "../../types" {
3
+ declare module "../../types.js" {
3
4
  interface LightboxProps {
4
5
  /** Slideshow plugin settings */
5
6
  slideshow?: {
7
+ /** Slideshow plugin ref */
8
+ ref?: React.ForwardedRef<SlideshowRef>;
6
9
  /** if `true`, slideshow is turned on automatically when the lightbox opens */
7
10
  autoplay?: boolean;
8
11
  /** slideshow delay in milliseconds */
9
12
  delay?: number;
10
13
  };
11
14
  }
12
- /** `render.buttonSlideshow` render function props */
13
- type RenderSlideshowButtonProps = {
14
- /** current slideshow autoplay status */
15
- playing: boolean;
16
- /** toggle slideshow autoplay status */
17
- togglePlaying: () => void;
18
- /** if `true`, the button is disabled */
19
- disabled: boolean;
20
- };
21
15
  interface Render {
22
16
  /** render custom Slideshow Play icon */
23
17
  iconSlideshowPlay?: RenderFunction;
24
18
  /** render custom Slideshow Pause icon */
25
19
  iconSlideshowPause?: RenderFunction;
26
20
  /** render custom Slideshow button */
27
- buttonSlideshow?: RenderFunction<RenderSlideshowButtonProps>;
21
+ buttonSlideshow?: RenderFunction<SlideshowRef>;
22
+ }
23
+ /** Slideshow plugin ref */
24
+ interface SlideshowRef {
25
+ /** current slideshow playback status */
26
+ playing: boolean;
27
+ /** if `true`, the slideshow playback is disabled */
28
+ disabled: boolean;
29
+ /** start the slideshow playback */
30
+ play: Callback;
31
+ /** pause the slideshow playback */
32
+ pause: Callback;
28
33
  }
29
34
  }
30
35
  export default Slideshow;
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { LightboxProps } from "../../types.js";
3
+ export declare const defaultSlideshowProps: {
4
+ autoplay: boolean;
5
+ delay: number;
6
+ ref: null;
7
+ };
8
+ export declare const resolveSlideshowProps: (slideshow: LightboxProps["slideshow"]) => {
9
+ ref: import("react").ForwardedRef<import("../../types.js").SlideshowRef>;
10
+ autoplay: boolean;
11
+ delay: number;
12
+ };
@@ -0,0 +1,9 @@
1
+ export const defaultSlideshowProps = {
2
+ autoplay: false,
3
+ delay: 3000,
4
+ ref: null,
5
+ };
6
+ export const resolveSlideshowProps = (slideshow) => ({
7
+ ...defaultSlideshowProps,
8
+ ...slideshow,
9
+ });
@@ -1,19 +1,15 @@
1
- import * as React from "react";
2
- import { ContainerRect, ImageFit, LightboxProps, Slide } from "../../types.js";
1
+ /// <reference types="react" />
2
+ import { Slide } from "../../types.js";
3
3
  export type FadeSettings = {
4
4
  duration: number;
5
5
  delay: number;
6
6
  };
7
7
  export type ThumbnailProps = {
8
- rect: ContainerRect;
9
8
  slide: Slide | null;
10
9
  onClick: () => void;
11
10
  active: boolean;
12
11
  fadeIn?: FadeSettings;
13
12
  fadeOut?: FadeSettings;
14
13
  placeholder: boolean;
15
- render: LightboxProps["render"];
16
- imageFit: ImageFit;
17
- style?: React.CSSProperties;
18
14
  };
19
- export declare function Thumbnail({ rect, slide, onClick, active, fadeIn, fadeOut, placeholder, render, imageFit, style, }: ThumbnailProps): JSX.Element;
15
+ export declare function Thumbnail({ slide, onClick, active, fadeIn, fadeOut, placeholder }: ThumbnailProps): JSX.Element;
@@ -1,6 +1,7 @@
1
1
  import * as React from "react";
2
- import { CLASS_FLEX_CENTER, CLASS_FULLSIZE, clsx, createIcon, cssClass, cssVar, ELEMENT_ICON, ImageSlide, isImageSlide, makeComposePrefix, } from "../../core/index.js";
2
+ import { CLASS_FLEX_CENTER, CLASS_FULLSIZE, clsx, createIcon, cssClass, cssVar, ELEMENT_ICON, ImageSlide, isImageSlide, makeComposePrefix, useLightboxProps, } from "../../core/index.js";
3
3
  import { cssPrefix, cssThumbnailPrefix } from "./utils.js";
4
+ import { useThumbnailsProps } from "./props.js";
4
5
  const VideoThumbnailIcon = createIcon("VideoThumbnail", React.createElement("path", { d: "M10 16.5l6-4.5-6-4.5v9zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z" }));
5
6
  const UnknownThumbnailIcon = createIcon("UnknownThumbnail", React.createElement("path", { d: "M23 18V6c0-1.1-.9-2-2-2H3c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2zM8.5 12.5l2.5 3.01L14.5 11l4.5 6H5l3.5-4.5z" }));
6
7
  function renderThumbnail({ slide, render, rect, imageFit }) {
@@ -28,7 +29,10 @@ const fadeOutPrefix = makeComposePrefix("fadeout");
28
29
  const placeholderPrefix = makeComposePrefix("placeholder");
29
30
  const DELAY = "delay";
30
31
  const DURATION = "duration";
31
- export function Thumbnail({ rect, slide, onClick, active, fadeIn, fadeOut, placeholder, render, imageFit, style, }) {
32
+ export function Thumbnail({ slide, onClick, active, fadeIn, fadeOut, placeholder }) {
33
+ const { render, styles } = useLightboxProps();
34
+ const { width, height, imageFit } = useThumbnailsProps();
35
+ const rect = { width, height };
32
36
  return (React.createElement("button", { type: "button", className: clsx(cssClass(CLASS_FLEX_CENTER), cssClass(cssThumbnailPrefix()), active && cssClass(cssThumbnailPrefix(activePrefix())), fadeIn && cssClass(cssThumbnailPrefix(fadeInPrefix())), fadeOut && cssClass(cssThumbnailPrefix(fadeOutPrefix())), placeholder && cssClass(cssThumbnailPrefix(placeholderPrefix()))), style: {
33
37
  ...(fadeIn
34
38
  ? {
@@ -42,6 +46,6 @@ export function Thumbnail({ rect, slide, onClick, active, fadeIn, fadeOut, place
42
46
  [cssVar(cssThumbnailPrefix(fadeOutPrefix(DELAY)))]: `${fadeOut.delay}ms`,
43
47
  }
44
48
  : null),
45
- ...style,
49
+ ...styles.thumbnail,
46
50
  }, onClick: onClick }, slide && renderThumbnail({ slide, render, rect, imageFit })));
47
51
  }
@@ -1,14 +1,3 @@
1
- import { Plugin } from "../../types.js";
2
- export declare const defaultThumbnailsProps: {
3
- position: "bottom";
4
- width: number;
5
- height: number;
6
- border: number;
7
- borderRadius: number;
8
- padding: number;
9
- gap: number;
10
- imageFit: "contain";
11
- vignette: boolean;
12
- };
1
+ import { PluginProps } from "../../types.js";
13
2
  /** Thumbnails plugin */
14
- export declare const Thumbnails: Plugin;
3
+ export declare function Thumbnails({ augment, contains, append, addParent }: PluginProps): void;
@@ -1,29 +1,16 @@
1
1
  import { createModule, MODULE_CONTROLLER, PLUGIN_FULLSCREEN, PLUGIN_THUMBNAILS } from "../../core/index.js";
2
- import { ThumbnailsComponent } from "./ThumbnailsContainer.js";
3
- export const defaultThumbnailsProps = {
4
- position: "bottom",
5
- width: 120,
6
- height: 80,
7
- border: 1,
8
- borderRadius: 4,
9
- padding: 4,
10
- gap: 16,
11
- imageFit: "contain",
12
- vignette: true,
13
- };
14
- export const Thumbnails = ({ augment, contains, append, addParent }) => {
2
+ import { resolveThumbnailsProps } from "./props.js";
3
+ import { ThumbnailsContainer } from "./ThumbnailsContainer.js";
4
+ export function Thumbnails({ augment, contains, append, addParent }) {
15
5
  augment(({ thumbnails, ...restProps }) => ({
16
- thumbnails: {
17
- ...defaultThumbnailsProps,
18
- ...thumbnails,
19
- },
6
+ thumbnails: resolveThumbnailsProps(thumbnails),
20
7
  ...restProps,
21
8
  }));
22
- const module = createModule(PLUGIN_THUMBNAILS, ThumbnailsComponent);
9
+ const module = createModule(PLUGIN_THUMBNAILS, ThumbnailsContainer);
23
10
  if (contains(PLUGIN_FULLSCREEN)) {
24
11
  append(PLUGIN_FULLSCREEN, module);
25
12
  }
26
13
  else {
27
14
  addParent(MODULE_CONTROLLER, module);
28
15
  }
29
- };
16
+ }
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { ComponentProps } from "../../types.js";
3
3
  /** Thumbnails plugin component */
4
- export declare function ThumbnailsComponent({ thumbnails: thumbnailsProps, slides, carousel, animation, render, styles, children, }: ComponentProps): JSX.Element;
4
+ export declare function ThumbnailsContainer({ children, ...props }: ComponentProps): JSX.Element;
@@ -1,14 +1,14 @@
1
1
  import * as React from "react";
2
- import { clsx, cssClass } from "../../core/index.js";
2
+ import { clsx, cssClass, LightboxPropsProvider } from "../../core/index.js";
3
3
  import { cssPrefix } from "./utils.js";
4
4
  import { ThumbnailsTrack } from "./ThumbnailsTrack.js";
5
- import { defaultThumbnailsProps } from "./Thumbnails.js";
6
- export function ThumbnailsComponent({ thumbnails: thumbnailsProps, slides, carousel, animation, render, styles, children, }) {
7
- const thumbnails = { ...defaultThumbnailsProps, ...thumbnailsProps };
8
- const ref = React.useRef(null);
9
- const track = (React.createElement(ThumbnailsTrack, { container: ref, slides: slides, thumbnails: thumbnails, carousel: carousel, animation: animation, render: render, thumbnailRect: { width: thumbnails.width, height: thumbnails.height }, styles: styles }));
10
- return (React.createElement("div", { ref: ref, className: clsx(cssClass(cssPrefix()), cssClass(cssPrefix(`${thumbnails.position}`))) },
11
- (thumbnails.position === "start" || thumbnails.position === "top") && track,
12
- React.createElement("div", { className: cssClass(cssPrefix("wrapper")) }, children),
13
- (thumbnails.position === "end" || thumbnails.position === "bottom") && track));
5
+ import { resolveThumbnailsProps } from "./props.js";
6
+ export function ThumbnailsContainer({ children, ...props }) {
7
+ const containerRef = React.useRef(null);
8
+ const { position } = resolveThumbnailsProps(props.thumbnails);
9
+ return (React.createElement(LightboxPropsProvider, { ...props },
10
+ React.createElement("div", { ref: containerRef, className: clsx(cssClass(cssPrefix()), cssClass(cssPrefix(`${position}`))) },
11
+ ["start", "top"].includes(position) && React.createElement(ThumbnailsTrack, { containerRef: containerRef }),
12
+ React.createElement("div", { className: cssClass(cssPrefix("wrapper")) }, children),
13
+ ["end", "bottom"].includes(position) && React.createElement(ThumbnailsTrack, { containerRef: containerRef }))));
14
14
  }
@@ -1,9 +1,7 @@
1
1
  import * as React from "react";
2
- import { ContainerRect, DeepNonNullable, LightboxProps } from "../../types.js";
2
+ import { DeepNonNullable, LightboxProps } from "../../types.js";
3
3
  export type ThumbnailsInternal = DeepNonNullable<LightboxProps["thumbnails"]>;
4
- export type ThumbnailsTrackProps = Pick<LightboxProps, "slides" | "carousel" | "animation" | "render" | "styles"> & {
5
- container: React.RefObject<HTMLDivElement>;
6
- thumbnails: ThumbnailsInternal;
7
- thumbnailRect: ContainerRect;
4
+ export type ThumbnailsTrackProps = {
5
+ containerRef: React.RefObject<HTMLDivElement>;
8
6
  };
9
- export declare function ThumbnailsTrack({ container, slides, carousel, render, thumbnails, thumbnailRect, styles, }: ThumbnailsTrackProps): JSX.Element;
7
+ export declare function ThumbnailsTrack({ containerRef }: ThumbnailsTrackProps): JSX.Element;