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.
- package/dist/Lightbox.d.ts +1 -1
- package/dist/Lightbox.js +17 -13
- package/dist/core/components/IconButton.js +2 -2
- package/dist/core/components/ImageSlide.js +0 -3
- package/dist/core/config.d.ts +3 -3
- package/dist/core/config.js +18 -13
- package/dist/core/consts.d.ts +2 -4
- package/dist/core/consts.js +2 -4
- package/dist/core/contexts/Events.d.ts +3 -2
- package/dist/core/contexts/Events.js +3 -3
- package/dist/core/contexts/LightboxProps.d.ts +6 -0
- package/dist/core/contexts/LightboxProps.js +7 -0
- package/dist/core/contexts/LightboxState.d.ts +15 -15
- package/dist/core/contexts/LightboxState.js +33 -20
- package/dist/core/contexts/Timeouts.d.ts +1 -0
- package/dist/core/contexts/Timeouts.js +3 -3
- package/dist/core/contexts/index.d.ts +1 -0
- package/dist/core/contexts/index.js +1 -0
- package/dist/core/hooks/useAnimation.d.ts +4 -1
- package/dist/core/hooks/useAnimation.js +12 -3
- package/dist/core/hooks/useLoseFocus.js +3 -3
- package/dist/core/modules/Carousel.d.ts +1 -1
- package/dist/core/modules/Carousel.js +19 -24
- package/dist/core/modules/Controller.d.ts +15 -16
- package/dist/core/modules/Controller.js +68 -34
- package/dist/core/modules/Navigation.d.ts +4 -5
- package/dist/core/modules/Navigation.js +15 -12
- package/dist/core/modules/Portal.js +5 -4
- package/dist/core/modules/Root.d.ts +4 -0
- package/dist/core/modules/Root.js +7 -0
- package/dist/core/modules/Toolbar.d.ts +0 -6
- package/dist/core/modules/Toolbar.js +6 -8
- package/dist/core/modules/index.d.ts +1 -1
- package/dist/core/modules/index.js +1 -1
- package/dist/core/utils.d.ts +7 -10
- package/dist/core/utils.js +14 -14
- package/dist/plugins/captions/Captions.d.ts +2 -6
- package/dist/plugins/captions/Captions.js +17 -20
- package/dist/plugins/captions/Description.d.ts +2 -2
- package/dist/plugins/captions/Description.js +5 -3
- package/dist/plugins/captions/Title.js +2 -3
- package/dist/plugins/captions/captions.css +1 -0
- package/dist/plugins/captions/index.d.ts +2 -2
- package/dist/plugins/captions/props.d.ts +9 -0
- package/dist/plugins/captions/props.js +8 -0
- package/dist/plugins/captions/utils.d.ts +1 -1
- package/dist/plugins/captions/utils.js +1 -3
- package/dist/plugins/fullscreen/Fullscreen.d.ts +2 -2
- package/dist/plugins/fullscreen/Fullscreen.js +5 -3
- package/dist/plugins/fullscreen/FullscreenButton.js +8 -5
- package/dist/plugins/fullscreen/FullscreenContext.d.ts +5 -9
- package/dist/plugins/fullscreen/FullscreenContext.js +16 -26
- package/dist/plugins/fullscreen/index.d.ts +21 -10
- package/dist/plugins/fullscreen/props.d.ts +10 -0
- package/dist/plugins/fullscreen/props.js +8 -0
- package/dist/plugins/inline/Inline.d.ts +2 -2
- package/dist/plugins/inline/Inline.js +4 -7
- package/dist/plugins/inline/InlineContainer.d.ts +4 -0
- package/dist/plugins/inline/InlineContainer.js +5 -0
- package/dist/plugins/inline/index.d.ts +1 -1
- package/dist/plugins/slideshow/Slideshow.d.ts +2 -6
- package/dist/plugins/slideshow/Slideshow.js +7 -10
- package/dist/plugins/slideshow/SlideshowButton.js +7 -5
- package/dist/plugins/slideshow/SlideshowContext.d.ts +5 -9
- package/dist/plugins/slideshow/SlideshowContext.js +21 -12
- package/dist/plugins/slideshow/index.d.ts +16 -11
- package/dist/plugins/slideshow/props.d.ts +12 -0
- package/dist/plugins/slideshow/props.js +9 -0
- package/dist/plugins/thumbnails/Thumbnail.d.ts +3 -7
- package/dist/plugins/thumbnails/Thumbnail.js +7 -3
- package/dist/plugins/thumbnails/Thumbnails.d.ts +2 -13
- package/dist/plugins/thumbnails/Thumbnails.js +6 -19
- package/dist/plugins/thumbnails/ThumbnailsContainer.d.ts +1 -1
- package/dist/plugins/thumbnails/ThumbnailsContainer.js +10 -10
- package/dist/plugins/thumbnails/ThumbnailsTrack.d.ts +4 -6
- package/dist/plugins/thumbnails/ThumbnailsTrack.js +16 -14
- package/dist/plugins/thumbnails/index.d.ts +5 -5
- package/dist/plugins/thumbnails/props.d.ts +34 -0
- package/dist/plugins/thumbnails/props.js +20 -0
- package/dist/plugins/video/Video.d.ts +2 -6
- package/dist/plugins/video/Video.js +11 -11
- package/dist/plugins/video/VideoSlide.d.ts +1 -1
- package/dist/plugins/video/VideoSlide.js +3 -3
- package/dist/plugins/video/index.d.ts +39 -42
- package/dist/plugins/video/props.d.ts +29 -0
- package/dist/plugins/video/props.js +13 -0
- package/dist/plugins/zoom/ResponsiveImage.js +23 -15
- package/dist/plugins/zoom/Zoom.d.ts +0 -11
- package/dist/plugins/zoom/Zoom.js +11 -33
- package/dist/plugins/zoom/ZoomButton.d.ts +6 -5
- package/dist/plugins/zoom/ZoomButton.js +11 -33
- package/dist/plugins/zoom/ZoomButtonsGroup.d.ts +1 -4
- package/dist/plugins/zoom/ZoomButtonsGroup.js +6 -7
- package/dist/plugins/zoom/ZoomController.d.ts +12 -0
- package/dist/plugins/zoom/ZoomController.js +17 -0
- package/dist/plugins/zoom/ZoomToolbarControl.d.ts +2 -0
- package/dist/plugins/zoom/ZoomToolbarControl.js +12 -0
- package/dist/plugins/zoom/ZoomWrapper.d.ts +5 -0
- package/dist/plugins/zoom/ZoomWrapper.js +36 -0
- package/dist/plugins/zoom/hooks/index.d.ts +6 -0
- package/dist/plugins/zoom/hooks/index.js +6 -0
- package/dist/plugins/zoom/hooks/useZoomAnimation.d.ts +2 -0
- package/dist/plugins/zoom/hooks/useZoomAnimation.js +39 -0
- package/dist/plugins/zoom/hooks/useZoomCallback.d.ts +1 -0
- package/dist/plugins/zoom/hooks/useZoomCallback.js +12 -0
- package/dist/plugins/zoom/hooks/useZoomImageRect.d.ts +5 -0
- package/dist/plugins/zoom/hooks/useZoomImageRect.js +41 -0
- package/dist/plugins/zoom/hooks/useZoomProps.d.ts +13 -0
- package/dist/plugins/zoom/hooks/useZoomProps.js +6 -0
- package/dist/plugins/zoom/hooks/useZoomSensors.d.ts +3 -0
- package/dist/plugins/zoom/hooks/useZoomSensors.js +154 -0
- package/dist/plugins/zoom/hooks/useZoomState.d.ts +12 -0
- package/dist/plugins/zoom/hooks/useZoomState.js +63 -0
- package/dist/plugins/zoom/index.d.ts +37 -24
- package/dist/plugins/zoom/index.js +0 -2
- package/dist/plugins/zoom/props.d.ts +25 -0
- package/dist/plugins/zoom/props.js +15 -0
- package/dist/props.d.ts +0 -4
- package/dist/props.js +10 -5
- package/dist/types.d.ts +173 -117
- package/package.json +41 -11
- package/dist/core/modules/Core.d.ts +0 -4
- package/dist/core/modules/Core.js +0 -10
- package/dist/plugins/captions/CaptionsContext.d.ts +0 -7
- package/dist/plugins/captions/CaptionsContext.js +0 -11
- package/dist/plugins/zoom/ZoomContainer.d.ts +0 -9
- package/dist/plugins/zoom/ZoomContainer.js +0 -316
- package/dist/plugins/zoom/ZoomContext.d.ts +0 -11
- package/dist/plugins/zoom/ZoomContext.js +0 -20
|
@@ -1,33 +1,36 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, CLASS_FLEX_CENTER, cleanup, clsx, cssClass, cssVar, getSlide, useAnimation, useEventCallback, useEvents, useLightboxState, useRTL, } from "../../core/index.js";
|
|
2
|
+
import { ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, CLASS_FLEX_CENTER, cleanup, clsx, cssClass, cssVar, getSlide, useAnimation, useEventCallback, useEvents, useLightboxProps, useLightboxState, useRTL, } from "../../core/index.js";
|
|
3
3
|
import { cssPrefix, cssThumbnailPrefix } from "./utils.js";
|
|
4
4
|
import { Thumbnail } from "./Thumbnail.js";
|
|
5
|
-
import { defaultThumbnailsProps } from "./
|
|
5
|
+
import { defaultThumbnailsProps, useThumbnailsProps } from "./props.js";
|
|
6
6
|
function isHorizontal(position) {
|
|
7
7
|
return ["top", "bottom"].includes(position);
|
|
8
8
|
}
|
|
9
9
|
function boxSize(thumbnails, dimension, includeGap) {
|
|
10
10
|
return dimension + 2 * (thumbnails.border + thumbnails.padding) + (includeGap ? thumbnails.gap : 0);
|
|
11
11
|
}
|
|
12
|
-
export function ThumbnailsTrack({
|
|
12
|
+
export function ThumbnailsTrack({ containerRef }) {
|
|
13
13
|
const track = React.useRef(null);
|
|
14
|
-
const {
|
|
14
|
+
const { carousel, styles } = useLightboxProps();
|
|
15
|
+
const { slides, globalIndex, animation } = useLightboxState().state;
|
|
15
16
|
const { publish, subscribe } = useEvents();
|
|
16
17
|
const isRTL = useRTL();
|
|
18
|
+
const thumbnails = useThumbnailsProps();
|
|
19
|
+
const { position, width, height, border, borderRadius, padding, gap, vignette } = thumbnails;
|
|
17
20
|
const index = globalIndex;
|
|
18
21
|
const animationDuration = (animation === null || animation === void 0 ? void 0 : animation.duration) || 0;
|
|
19
22
|
const offset = (animationDuration > 0 && (animation === null || animation === void 0 ? void 0 : animation.increment)) || 0;
|
|
20
|
-
const
|
|
21
|
-
keyframes: isHorizontal(
|
|
23
|
+
const { prepareAnimation } = useAnimation(track, (snapshot) => ({
|
|
24
|
+
keyframes: isHorizontal(position)
|
|
22
25
|
? [
|
|
23
26
|
{
|
|
24
|
-
transform: `translateX(${(isRTL ? -1 : 1) * boxSize(thumbnails,
|
|
27
|
+
transform: `translateX(${(isRTL ? -1 : 1) * boxSize(thumbnails, width, true) * offset + snapshot}px)`,
|
|
25
28
|
},
|
|
26
29
|
{ transform: "translateX(0)" },
|
|
27
30
|
]
|
|
28
31
|
: [
|
|
29
32
|
{
|
|
30
|
-
transform: `translateY(${boxSize(thumbnails,
|
|
33
|
+
transform: `translateY(${boxSize(thumbnails, height, true) * offset + snapshot}px)`,
|
|
31
34
|
},
|
|
32
35
|
{ transform: "translateY(0)" },
|
|
33
36
|
],
|
|
@@ -36,17 +39,17 @@ export function ThumbnailsTrack({ container, slides, carousel, render, thumbnail
|
|
|
36
39
|
}));
|
|
37
40
|
const handleControllerSwipe = useEventCallback(() => {
|
|
38
41
|
let animationOffset;
|
|
39
|
-
if (
|
|
40
|
-
const containerRect =
|
|
42
|
+
if (containerRef.current && track.current) {
|
|
43
|
+
const containerRect = containerRef.current.getBoundingClientRect();
|
|
41
44
|
const trackRect = track.current.getBoundingClientRect();
|
|
42
|
-
animationOffset = isHorizontal(
|
|
45
|
+
animationOffset = isHorizontal(position)
|
|
43
46
|
? trackRect.left - containerRect.left - (containerRect.width - trackRect.width) / 2
|
|
44
47
|
: trackRect.top - containerRect.top - (containerRect.height - trackRect.height) / 2;
|
|
45
48
|
}
|
|
46
49
|
else {
|
|
47
50
|
animationOffset = 0;
|
|
48
51
|
}
|
|
49
|
-
|
|
52
|
+
prepareAnimation(animationOffset);
|
|
50
53
|
});
|
|
51
54
|
React.useEffect(() => cleanup(subscribe(ACTION_SWIPE, handleControllerSwipe)), [subscribe, handleControllerSwipe]);
|
|
52
55
|
const { finite } = carousel;
|
|
@@ -89,7 +92,6 @@ export function ThumbnailsTrack({ container, slides, carousel, render, thumbnail
|
|
|
89
92
|
publish(ACTION_PREV, { count: index - slideIndex });
|
|
90
93
|
}
|
|
91
94
|
};
|
|
92
|
-
const { width, height, border, borderRadius, padding, gap, imageFit, vignette } = thumbnails;
|
|
93
95
|
return (React.createElement("div", { className: clsx(cssClass(cssPrefix("container")), cssClass(CLASS_FLEX_CENTER)), style: {
|
|
94
96
|
...(width !== defaultThumbnailsProps.width
|
|
95
97
|
? { [cssVar(cssThumbnailPrefix("width"))]: `${boxSize(thumbnails, width)}px` }
|
|
@@ -130,7 +132,7 @@ export function ThumbnailsTrack({ container, slides, carousel, render, thumbnail
|
|
|
130
132
|
: -offset - (slideIndex - (index + preload))) * fadeAnimationDuration,
|
|
131
133
|
}
|
|
132
134
|
: undefined;
|
|
133
|
-
return (React.createElement(Thumbnail, { key: slideIndex,
|
|
135
|
+
return (React.createElement(Thumbnail, { key: slideIndex, slide: slide, active: slideIndex === index, fadeIn: fadeIn, fadeOut: fadeOut, placeholder: Boolean(placeholder), onClick: handleClick(slideIndex) }));
|
|
134
136
|
})),
|
|
135
137
|
vignette && React.createElement("div", { className: cssClass(cssPrefix("vignette")) })));
|
|
136
138
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Thumbnails } from "./Thumbnails.js";
|
|
2
2
|
type Position = "top" | "bottom" | "start" | "end";
|
|
3
|
-
declare module "../../types" {
|
|
3
|
+
declare module "../../types.js" {
|
|
4
4
|
interface LightboxProps {
|
|
5
5
|
/** Thumbnails plugin settings */
|
|
6
6
|
thumbnails?: {
|
|
@@ -24,6 +24,10 @@ declare module "../../types" {
|
|
|
24
24
|
vignette?: boolean;
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
+
interface Render {
|
|
28
|
+
/** render custom thumbnail */
|
|
29
|
+
thumbnail?: RenderFunction<RenderThumbnailProps>;
|
|
30
|
+
}
|
|
27
31
|
/** `render.thumbnail` render function props */
|
|
28
32
|
type RenderThumbnailProps = {
|
|
29
33
|
slide: Slide;
|
|
@@ -31,10 +35,6 @@ declare module "../../types" {
|
|
|
31
35
|
render: Render;
|
|
32
36
|
imageFit: ImageFit;
|
|
33
37
|
};
|
|
34
|
-
interface Render {
|
|
35
|
-
/** render custom thumbnail */
|
|
36
|
-
thumbnail?: RenderFunction<RenderThumbnailProps>;
|
|
37
|
-
}
|
|
38
38
|
interface SlotType {
|
|
39
39
|
/** thumbnail customization slot */
|
|
40
40
|
thumbnail: "thumbnail";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { LightboxProps } 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
|
+
};
|
|
13
|
+
export declare const resolveThumbnailsProps: (thumbnails: LightboxProps["thumbnails"]) => {
|
|
14
|
+
position: "end" | "start" | "bottom" | "top";
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
border: number;
|
|
18
|
+
borderRadius: number;
|
|
19
|
+
padding: number;
|
|
20
|
+
gap: number;
|
|
21
|
+
imageFit: import("../../types.js").ImageFit;
|
|
22
|
+
vignette: boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare function useThumbnailsProps(): {
|
|
25
|
+
position: "end" | "start" | "bottom" | "top";
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
border: number;
|
|
29
|
+
borderRadius: number;
|
|
30
|
+
padding: number;
|
|
31
|
+
gap: number;
|
|
32
|
+
imageFit: import("../../types.js").ImageFit;
|
|
33
|
+
vignette: boolean;
|
|
34
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useLightboxProps } from "../../core/index.js";
|
|
2
|
+
export const defaultThumbnailsProps = {
|
|
3
|
+
position: "bottom",
|
|
4
|
+
width: 120,
|
|
5
|
+
height: 80,
|
|
6
|
+
border: 1,
|
|
7
|
+
borderRadius: 4,
|
|
8
|
+
padding: 4,
|
|
9
|
+
gap: 16,
|
|
10
|
+
imageFit: "contain",
|
|
11
|
+
vignette: true,
|
|
12
|
+
};
|
|
13
|
+
export const resolveThumbnailsProps = (thumbnails) => ({
|
|
14
|
+
...defaultThumbnailsProps,
|
|
15
|
+
...thumbnails,
|
|
16
|
+
});
|
|
17
|
+
export function useThumbnailsProps() {
|
|
18
|
+
const { thumbnails } = useLightboxProps();
|
|
19
|
+
return resolveThumbnailsProps(thumbnails);
|
|
20
|
+
}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const defaultVideoProps: {
|
|
3
|
-
controls: boolean;
|
|
4
|
-
playsInline: boolean;
|
|
5
|
-
};
|
|
1
|
+
import { PluginProps } from "../../types.js";
|
|
6
2
|
/** Video plugin */
|
|
7
|
-
export declare
|
|
3
|
+
export declare function Video({ augment }: PluginProps): void;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { resolveVideoProps } from "./props.js";
|
|
2
3
|
import { VideoSlide } from "./VideoSlide.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
augment(({ render: { slide: renderSlide, ...restRender }, video: videoProps, ...restProps }) => ({
|
|
4
|
+
function isVideoSlide(slide) {
|
|
5
|
+
return slide.type === "video";
|
|
6
|
+
}
|
|
7
|
+
export function Video({ augment }) {
|
|
8
|
+
augment(({ render: { slide: renderSlide, ...restRender }, video, ...restProps }) => ({
|
|
9
9
|
render: {
|
|
10
|
-
slide: (slide, offset, rect) => {
|
|
11
|
-
if (slide
|
|
10
|
+
slide: ({ slide, offset, rect }) => {
|
|
11
|
+
if (isVideoSlide(slide)) {
|
|
12
12
|
return (React.createElement(VideoSlide, { key: `${slide.sources.map((source) => source.src).join(" ")}`, slide: slide, offset: offset }));
|
|
13
13
|
}
|
|
14
|
-
return renderSlide === null || renderSlide === void 0 ? void 0 : renderSlide(slide, offset, rect);
|
|
14
|
+
return renderSlide === null || renderSlide === void 0 ? void 0 : renderSlide({ slide, offset, rect });
|
|
15
15
|
},
|
|
16
16
|
...restRender,
|
|
17
17
|
},
|
|
18
|
-
video:
|
|
18
|
+
video: resolveVideoProps(video),
|
|
19
19
|
...restProps,
|
|
20
20
|
}));
|
|
21
|
-
}
|
|
21
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, CLASS_FLEX_CENTER, clsx, cssClass, useContainerRect,
|
|
3
|
-
import {
|
|
2
|
+
import { ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, CLASS_FLEX_CENTER, clsx, cssClass, useContainerRect, useEventCallback, useEvents, } from "../../core/index.js";
|
|
3
|
+
import { useVideoProps } from "./props.js";
|
|
4
4
|
export function VideoSlide({ slide, offset }) {
|
|
5
|
+
const video = useVideoProps();
|
|
5
6
|
const { publish } = useEvents();
|
|
6
7
|
const { setContainerRef, containerRect } = useContainerRect();
|
|
7
8
|
const videoRef = React.useRef(null);
|
|
8
|
-
const video = { ...defaultVideoProps, ...useController().getLightboxProps().video };
|
|
9
9
|
React.useEffect(() => {
|
|
10
10
|
if (offset !== 0 && videoRef.current && !videoRef.current.paused) {
|
|
11
11
|
videoRef.current.pause();
|
|
@@ -1,55 +1,52 @@
|
|
|
1
|
-
import { GenericSlide } from "../../types.js";
|
|
2
1
|
import { Video } from "./Video.js";
|
|
3
2
|
import { ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING } from "../../core/consts.js";
|
|
4
|
-
|
|
5
|
-
export interface SlideVideo extends GenericSlide {
|
|
6
|
-
/** video slide type marker */
|
|
7
|
-
type: "video";
|
|
8
|
-
/** video placeholder image */
|
|
9
|
-
poster?: string;
|
|
10
|
-
/** video width in pixels */
|
|
11
|
-
width?: number;
|
|
12
|
-
/** video height in pixels */
|
|
13
|
-
height?: number;
|
|
14
|
-
/** if `true`, the video automatically begins to play */
|
|
15
|
-
autoPlay?: boolean;
|
|
16
|
-
/** if `true`, the browser will offer controls to allow the user to control video playback */
|
|
17
|
-
controls?: boolean;
|
|
18
|
-
/** indicates what controls to show */
|
|
19
|
-
controlsList?: string;
|
|
20
|
-
/** indicates whether to use CORS to fetch the related video */
|
|
21
|
-
crossOrigin?: string;
|
|
22
|
-
/** video preload setting */
|
|
23
|
-
preload?: string;
|
|
24
|
-
/** if `true`, the browser will automatically seek back to the start upon reaching the end of the video */
|
|
25
|
-
loop?: boolean;
|
|
26
|
-
/** the default setting of the audio contained in the video */
|
|
27
|
-
muted?: boolean;
|
|
28
|
-
/** if `true`, the video is to be played "inline", that is within the element's playback area */
|
|
29
|
-
playsInline?: boolean;
|
|
30
|
-
/** prevents the browser from suggesting a Picture-in-Picture context menu */
|
|
31
|
-
disablePictureInPicture?: boolean;
|
|
32
|
-
/** disables the capability of remote playback */
|
|
33
|
-
disableRemotePlayback?: boolean;
|
|
34
|
-
/** an array of video files */
|
|
35
|
-
sources: {
|
|
36
|
-
/** video source URL */
|
|
37
|
-
src: string;
|
|
38
|
-
/** video source type (e.g., `video/mp4`) */
|
|
39
|
-
type: string;
|
|
40
|
-
}[];
|
|
41
|
-
}
|
|
42
|
-
declare module "../../types" {
|
|
3
|
+
declare module "../../types.js" {
|
|
43
4
|
interface SlideTypes {
|
|
44
5
|
/** video slide type */
|
|
45
|
-
|
|
6
|
+
video: SlideVideo;
|
|
7
|
+
}
|
|
8
|
+
/** Video slide attributes */
|
|
9
|
+
interface SlideVideo extends GenericSlide {
|
|
10
|
+
/** video placeholder image */
|
|
11
|
+
poster?: string;
|
|
12
|
+
/** video width in pixels */
|
|
13
|
+
width?: number;
|
|
14
|
+
/** video height in pixels */
|
|
15
|
+
height?: number;
|
|
16
|
+
/** if `true`, the video automatically begins to play */
|
|
17
|
+
autoPlay?: boolean;
|
|
18
|
+
/** if `true`, the browser will offer controls to allow the user to control video playback */
|
|
19
|
+
controls?: boolean;
|
|
20
|
+
/** indicates what controls to show */
|
|
21
|
+
controlsList?: string;
|
|
22
|
+
/** indicates whether to use CORS to fetch the related video */
|
|
23
|
+
crossOrigin?: string;
|
|
24
|
+
/** video preload setting */
|
|
25
|
+
preload?: string;
|
|
26
|
+
/** if `true`, the browser will automatically seek back to the start upon reaching the end of the video */
|
|
27
|
+
loop?: boolean;
|
|
28
|
+
/** the default setting of the audio contained in the video */
|
|
29
|
+
muted?: boolean;
|
|
30
|
+
/** if `true`, the video is to be played "inline", that is within the element's playback area */
|
|
31
|
+
playsInline?: boolean;
|
|
32
|
+
/** prevents the browser from suggesting a Picture-in-Picture context menu */
|
|
33
|
+
disablePictureInPicture?: boolean;
|
|
34
|
+
/** disables the capability of remote playback */
|
|
35
|
+
disableRemotePlayback?: boolean;
|
|
36
|
+
/** an array of video files */
|
|
37
|
+
sources: {
|
|
38
|
+
/** video source URL */
|
|
39
|
+
src: string;
|
|
40
|
+
/** video source type (e.g., `video/mp4`) */
|
|
41
|
+
type: string;
|
|
42
|
+
}[];
|
|
46
43
|
}
|
|
47
44
|
interface LightboxProps {
|
|
48
45
|
/** video plugin settings */
|
|
49
46
|
video?: Pick<SlideVideo, "autoPlay" | "controls" | "controlsList" | "crossOrigin" | "preload" | "loop" | "muted" | "playsInline" | "disablePictureInPicture" | "disableRemotePlayback">;
|
|
50
47
|
}
|
|
51
48
|
}
|
|
52
|
-
declare module "../../core" {
|
|
49
|
+
declare module "../../core/index.js" {
|
|
53
50
|
interface EventTypes {
|
|
54
51
|
[ACTIVE_SLIDE_LOADING]: void;
|
|
55
52
|
[ACTIVE_SLIDE_PLAYING]: void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LightboxProps } from "../../types.js";
|
|
2
|
+
export declare const defaultVideoProps: {
|
|
3
|
+
controls: boolean;
|
|
4
|
+
playsInline: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare const resolveVideoProps: (video: LightboxProps["video"]) => {
|
|
7
|
+
autoPlay?: boolean | undefined;
|
|
8
|
+
controls: boolean;
|
|
9
|
+
controlsList?: string | undefined;
|
|
10
|
+
crossOrigin?: string | undefined;
|
|
11
|
+
preload?: string | undefined;
|
|
12
|
+
loop?: boolean | undefined;
|
|
13
|
+
muted?: boolean | undefined;
|
|
14
|
+
playsInline: boolean;
|
|
15
|
+
disablePictureInPicture?: boolean | undefined;
|
|
16
|
+
disableRemotePlayback?: boolean | undefined;
|
|
17
|
+
};
|
|
18
|
+
export declare function useVideoProps(): {
|
|
19
|
+
autoPlay?: boolean | undefined;
|
|
20
|
+
controls: boolean;
|
|
21
|
+
controlsList?: string | undefined;
|
|
22
|
+
crossOrigin?: string | undefined;
|
|
23
|
+
preload?: string | undefined;
|
|
24
|
+
loop?: boolean | undefined;
|
|
25
|
+
muted?: boolean | undefined;
|
|
26
|
+
playsInline: boolean;
|
|
27
|
+
disablePictureInPicture?: boolean | undefined;
|
|
28
|
+
disableRemotePlayback?: boolean | undefined;
|
|
29
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useLightboxProps } from "../../core/index.js";
|
|
2
|
+
export const defaultVideoProps = {
|
|
3
|
+
controls: true,
|
|
4
|
+
playsInline: true,
|
|
5
|
+
};
|
|
6
|
+
export const resolveVideoProps = (video) => ({
|
|
7
|
+
...defaultVideoProps,
|
|
8
|
+
...video,
|
|
9
|
+
});
|
|
10
|
+
export function useVideoProps() {
|
|
11
|
+
const { video } = useLightboxProps();
|
|
12
|
+
return resolveVideoProps(video);
|
|
13
|
+
}
|
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { devicePixelRatio, ImageSlide, isImageFitCover, useEventCallback, useLayoutEffect, } from "../../core/index.js";
|
|
2
|
+
import { devicePixelRatio, ImageSlide, isImageFitCover, UNKNOWN_ACTION_TYPE, useEventCallback, useLayoutEffect, } from "../../core/index.js";
|
|
3
3
|
export function isResponsiveImageSlide(slide) {
|
|
4
4
|
var _a;
|
|
5
5
|
return (((_a = slide.srcSet) === null || _a === void 0 ? void 0 : _a.length) || 0) > 0;
|
|
6
6
|
}
|
|
7
|
+
function reducer({ current, preload }, { type, source }) {
|
|
8
|
+
switch (type) {
|
|
9
|
+
case "fetch":
|
|
10
|
+
if (!current) {
|
|
11
|
+
return { current: source };
|
|
12
|
+
}
|
|
13
|
+
return { current, preload: source };
|
|
14
|
+
case "done":
|
|
15
|
+
if (source === preload) {
|
|
16
|
+
return { current: source };
|
|
17
|
+
}
|
|
18
|
+
return { current, preload };
|
|
19
|
+
default:
|
|
20
|
+
throw new Error(UNKNOWN_ACTION_TYPE);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
7
23
|
export function ResponsiveImage(props) {
|
|
8
24
|
var _a, _b;
|
|
9
|
-
const [
|
|
10
|
-
const { current, preload } = state;
|
|
25
|
+
const [{ current, preload }, dispatch] = React.useReducer(reducer, {});
|
|
11
26
|
const { slide: image, rect, imageFit, render } = props;
|
|
12
27
|
const srcSet = image.srcSet.sort((a, b) => a.width - b.width);
|
|
13
28
|
const width = (_a = image.width) !== null && _a !== void 0 ? _a : srcSet[srcSet.length - 1].width;
|
|
@@ -16,22 +31,15 @@ export function ResponsiveImage(props) {
|
|
|
16
31
|
const maxWidth = Math.max(...srcSet.map((x) => x.width));
|
|
17
32
|
const targetWidth = Math.min((cover ? Math.max : Math.min)(rect.width, width * (rect.height / height)), maxWidth);
|
|
18
33
|
const pixelDensity = devicePixelRatio();
|
|
19
|
-
const
|
|
34
|
+
const handleResize = useEventCallback(() => {
|
|
20
35
|
var _a;
|
|
21
36
|
const targetSource = (_a = srcSet.find((x) => x.width >= targetWidth * pixelDensity)) !== null && _a !== void 0 ? _a : srcSet[srcSet.length - 1];
|
|
22
|
-
if (!current) {
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
else if (srcSet.findIndex((x) => x.src === current) < srcSet.findIndex((x) => x === targetSource)) {
|
|
26
|
-
setState((prev) => ({ ...prev, preload: targetSource.src }));
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
useLayoutEffect(handleSourceChange, [rect === null || rect === void 0 ? void 0 : rect.width, rect === null || rect === void 0 ? void 0 : rect.height, pixelDensity, image.src, handleSourceChange]);
|
|
30
|
-
const handlePreload = useEventCallback((currentPreload) => {
|
|
31
|
-
if (currentPreload === preload) {
|
|
32
|
-
setState((prev) => ({ ...prev, current: preload, preload: undefined }));
|
|
37
|
+
if (!current || srcSet.findIndex((x) => x.src === current) < srcSet.findIndex((x) => x === targetSource)) {
|
|
38
|
+
dispatch({ type: "fetch", source: targetSource.src });
|
|
33
39
|
}
|
|
34
40
|
});
|
|
41
|
+
useLayoutEffect(handleResize, [rect.width, rect.height, pixelDensity, handleResize]);
|
|
42
|
+
const handlePreload = useEventCallback((currentPreload) => dispatch({ type: "done", source: currentPreload }));
|
|
35
43
|
const style = {
|
|
36
44
|
WebkitTransform: "translateZ(0)",
|
|
37
45
|
};
|
|
@@ -1,14 +1,3 @@
|
|
|
1
1
|
import { Plugin } from "../../types.js";
|
|
2
|
-
export declare const defaultZoomProps: {
|
|
3
|
-
maxZoomPixelRatio: number;
|
|
4
|
-
zoomInMultiplier: number;
|
|
5
|
-
doubleTapDelay: number;
|
|
6
|
-
doubleClickDelay: number;
|
|
7
|
-
doubleClickMaxStops: number;
|
|
8
|
-
keyboardMoveDistance: number;
|
|
9
|
-
wheelZoomDistanceFactor: number;
|
|
10
|
-
pinchZoomDistanceFactor: number;
|
|
11
|
-
scrollToZoom: boolean;
|
|
12
|
-
};
|
|
13
2
|
/** Zoom plugin */
|
|
14
3
|
export declare const Zoom: Plugin;
|
|
@@ -1,40 +1,18 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { createModule, isImageSlide,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
doubleClickMaxStops: 2,
|
|
12
|
-
keyboardMoveDistance: 50,
|
|
13
|
-
wheelZoomDistanceFactor: 100,
|
|
14
|
-
pinchZoomDistanceFactor: 100,
|
|
15
|
-
scrollToZoom: false,
|
|
16
|
-
};
|
|
17
|
-
export const Zoom = ({ augment, append }) => {
|
|
18
|
-
augment(({ toolbar: { buttons, ...restToolbar }, render, carousel, animation, zoom, on, ...restProps }) => ({
|
|
19
|
-
toolbar: {
|
|
20
|
-
buttons: [React.createElement(ZoomButtonsGroup, { key: PLUGIN_ZOOM, labels: restProps.labels, render: render }), ...buttons],
|
|
21
|
-
...restToolbar,
|
|
22
|
-
},
|
|
2
|
+
import { createModule, isImageSlide, PLUGIN_ZOOM } from "../../core/index.js";
|
|
3
|
+
import { resolveZoomProps } from "./props.js";
|
|
4
|
+
import { ZoomContextProvider } from "./ZoomController.js";
|
|
5
|
+
import { ZoomToolbarControl } from "./ZoomToolbarControl.js";
|
|
6
|
+
import { ZoomWrapper } from "./ZoomWrapper.js";
|
|
7
|
+
export const Zoom = ({ augment, addModule }) => {
|
|
8
|
+
augment(({ toolbar: { buttons, ...restToolbar }, render, zoom, ...restProps }) => ({
|
|
9
|
+
zoom: resolveZoomProps(zoom),
|
|
10
|
+
toolbar: { buttons: [React.createElement(ZoomToolbarControl, { key: PLUGIN_ZOOM }), ...buttons], ...restToolbar },
|
|
23
11
|
render: {
|
|
24
12
|
...render,
|
|
25
|
-
slide: (slide,
|
|
26
|
-
var _a;
|
|
27
|
-
return isImageSlide(slide) ? (React.createElement(ZoomContainer, { slide: slide, offset: offset, rect: rect, render: render, carousel: carousel, animation: animation, zoom: zoom, on: on })) : ((_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, slide, offset, rect));
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
zoom: {
|
|
31
|
-
...defaultZoomProps,
|
|
32
|
-
...zoom,
|
|
13
|
+
slide: (props) => { var _a; return isImageSlide(props.slide) ? React.createElement(ZoomWrapper, { render: render, ...props }) : (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, props); },
|
|
33
14
|
},
|
|
34
|
-
carousel,
|
|
35
|
-
animation,
|
|
36
|
-
on,
|
|
37
15
|
...restProps,
|
|
38
16
|
}));
|
|
39
|
-
|
|
17
|
+
addModule(createModule(PLUGIN_ZOOM, ZoomContextProvider));
|
|
40
18
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
zoomIn?: boolean | undefined;
|
|
2
|
+
/** Zoom button props */
|
|
3
|
+
export type ZoomButtonProps = {
|
|
4
|
+
zoomIn?: boolean;
|
|
6
5
|
onLoseFocus: () => void;
|
|
7
|
-
}
|
|
6
|
+
};
|
|
7
|
+
/** Zoom button */
|
|
8
|
+
export declare const ZoomButton: React.ForwardRefExoticComponent<ZoomButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { createIcon, IconButton, label,
|
|
3
|
-
import { useZoom } from "./
|
|
4
|
-
import { ACTION_ZOOM_IN, ACTION_ZOOM_OUT } from "./index.js";
|
|
2
|
+
import { createIcon, IconButton, label, useLightboxProps } from "../../core/index.js";
|
|
3
|
+
import { useZoom } from "./ZoomController.js";
|
|
5
4
|
const ZoomInIcon = createIcon("ZoomIn", React.createElement(React.Fragment, null,
|
|
6
5
|
React.createElement("path", { d: "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" }),
|
|
7
6
|
React.createElement("path", { d: "M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z" })));
|
|
8
7
|
const ZoomOutIcon = createIcon("ZoomOut", React.createElement("path", { d: "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14zM7 9h5v1H7z" }));
|
|
9
|
-
export const ZoomButton = React.forwardRef(({
|
|
8
|
+
export const ZoomButton = React.forwardRef(({ zoomIn, onLoseFocus }, ref) => {
|
|
10
9
|
const wasEnabled = React.useRef(false);
|
|
11
10
|
const wasFocused = React.useRef(false);
|
|
12
|
-
const {
|
|
13
|
-
const {
|
|
14
|
-
const disabled =
|
|
15
|
-
const onClick = () => publish(zoomIn ? ACTION_ZOOM_IN : ACTION_ZOOM_OUT);
|
|
16
|
-
const onFocus = React.useCallback(() => {
|
|
17
|
-
wasFocused.current = true;
|
|
18
|
-
}, []);
|
|
19
|
-
const onBlur = React.useCallback(() => {
|
|
20
|
-
wasFocused.current = false;
|
|
21
|
-
}, []);
|
|
11
|
+
const { zoom, maxZoom, zoomIn: zoomInCallback, zoomOut: zoomOutCallback, disabled: zoomDisabled } = useZoom();
|
|
12
|
+
const { render, labels } = useLightboxProps();
|
|
13
|
+
const disabled = zoomDisabled || (zoomIn ? zoom >= maxZoom : zoom <= 1);
|
|
22
14
|
React.useEffect(() => {
|
|
23
15
|
if (disabled && wasEnabled.current && wasFocused.current) {
|
|
24
16
|
onLoseFocus();
|
|
@@ -27,24 +19,10 @@ export const ZoomButton = React.forwardRef(({ labels, render, zoomIn, onLoseFocu
|
|
|
27
19
|
wasEnabled.current = true;
|
|
28
20
|
}
|
|
29
21
|
}, [disabled, onLoseFocus]);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
onClick,
|
|
36
|
-
onFocus,
|
|
37
|
-
onBlur,
|
|
38
|
-
})));
|
|
39
|
-
if (!zoomIn && render.buttonZoomOut)
|
|
40
|
-
return (React.createElement(React.Fragment, null, render.buttonZoomOut({
|
|
41
|
-
ref,
|
|
42
|
-
labels,
|
|
43
|
-
disabled,
|
|
44
|
-
onClick,
|
|
45
|
-
onFocus,
|
|
46
|
-
onBlur,
|
|
47
|
-
})));
|
|
48
|
-
return (React.createElement(IconButton, { ref: ref, label: label(labels, zoomIn ? "Zoom in" : "Zoom out"), icon: zoomIn ? ZoomInIcon : ZoomOutIcon, renderIcon: zoomIn ? render.iconZoomIn : render.iconZoomOut, disabled: disabled, onClick: onClick, onFocus: onFocus, onBlur: onBlur }));
|
|
22
|
+
return (React.createElement(IconButton, { ref: ref, disabled: disabled, label: label(labels, zoomIn ? "Zoom in" : "Zoom out"), icon: zoomIn ? ZoomInIcon : ZoomOutIcon, renderIcon: zoomIn ? render.iconZoomIn : render.iconZoomOut, onClick: () => (zoomIn ? zoomInCallback : zoomOutCallback)(), onFocus: () => {
|
|
23
|
+
wasFocused.current = true;
|
|
24
|
+
}, onBlur: () => {
|
|
25
|
+
wasFocused.current = false;
|
|
26
|
+
} }));
|
|
49
27
|
});
|
|
50
28
|
ZoomButton.displayName = "ZoomButton";
|
|
@@ -1,5 +1,2 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
3
|
-
type ZoomButtonsGroupProps = Pick<LightboxProps, "labels" | "render">;
|
|
4
|
-
export declare function ZoomButtonsGroup({ labels, render }: ZoomButtonsGroupProps): JSX.Element;
|
|
5
|
-
export {};
|
|
2
|
+
export default function ZoomButtonsGroup(): JSX.Element;
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { useController } from "../../core/index.js";
|
|
3
3
|
import { ZoomButton } from "./ZoomButton.js";
|
|
4
|
-
|
|
5
|
-
export function ZoomButtonsGroup({ labels, render }) {
|
|
4
|
+
export default function ZoomButtonsGroup() {
|
|
6
5
|
const zoomInRef = React.useRef(null);
|
|
7
6
|
const zoomOutRef = React.useRef(null);
|
|
8
|
-
const {
|
|
7
|
+
const { focus } = useController();
|
|
9
8
|
const focusSibling = React.useCallback((sibling) => {
|
|
10
9
|
var _a, _b;
|
|
11
10
|
if (!((_a = sibling.current) === null || _a === void 0 ? void 0 : _a.disabled)) {
|
|
12
11
|
(_b = sibling.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
13
12
|
}
|
|
14
13
|
else {
|
|
15
|
-
|
|
14
|
+
focus();
|
|
16
15
|
}
|
|
17
|
-
}, [
|
|
16
|
+
}, [focus]);
|
|
18
17
|
const focusZoomIn = React.useCallback(() => focusSibling(zoomInRef), [focusSibling]);
|
|
19
18
|
const focusZoomOut = React.useCallback(() => focusSibling(zoomOutRef), [focusSibling]);
|
|
20
19
|
return (React.createElement(React.Fragment, null,
|
|
21
|
-
React.createElement(ZoomButton, {
|
|
22
|
-
React.createElement(ZoomButton, { ref: zoomOutRef,
|
|
20
|
+
React.createElement(ZoomButton, { zoomIn: true, ref: zoomInRef, onLoseFocus: focusZoomOut }),
|
|
21
|
+
React.createElement(ZoomButton, { ref: zoomOutRef, onLoseFocus: focusZoomIn })));
|
|
23
22
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ComponentProps, ContainerRect, ZoomRef } from "../../types.js";
|
|
3
|
+
export type ActiveZoomWrapper = {
|
|
4
|
+
zoomWrapperRef: React.RefObject<HTMLDivElement>;
|
|
5
|
+
imageDimensions?: ContainerRect;
|
|
6
|
+
};
|
|
7
|
+
export type ZoomControllerContextType = ZoomRef & {
|
|
8
|
+
setZoomWrapper: React.Dispatch<React.SetStateAction<ActiveZoomWrapper | undefined>>;
|
|
9
|
+
};
|
|
10
|
+
export declare const ZoomControllerContext: React.Context<ZoomControllerContextType | null>;
|
|
11
|
+
export declare const useZoom: () => NonNullable<ZoomControllerContextType>;
|
|
12
|
+
export declare function ZoomContextProvider({ children }: ComponentProps): JSX.Element;
|