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.
- package/README.md +4 -8
- package/dist/Lightbox.d.ts +2 -2
- package/dist/Lightbox.js +11 -9
- package/dist/core/components/Icons.d.ts +1 -1
- package/dist/core/components/Icons.js +2 -2
- package/dist/core/components/ImageSlide.d.ts +1 -1
- package/dist/core/components/ImageSlide.js +5 -5
- package/dist/core/contexts/Events.d.ts +1 -1
- package/dist/core/contexts/Events.js +2 -2
- package/dist/core/contexts/LightboxState.d.ts +2 -3
- package/dist/core/contexts/LightboxState.js +2 -2
- package/dist/core/contexts/Timeouts.d.ts +1 -1
- package/dist/core/contexts/Timeouts.js +2 -2
- package/dist/core/hooks/useAnimation.d.ts +1 -1
- package/dist/core/hooks/useAnimation.js +4 -4
- package/dist/core/hooks/useContainerRect.d.ts +1 -1
- package/dist/core/hooks/useContainerRect.js +2 -2
- package/dist/core/hooks/useDelay.d.ts +1 -1
- package/dist/core/hooks/useDelay.js +2 -2
- package/dist/core/hooks/useEventCallback.d.ts +1 -1
- package/dist/core/hooks/useEventCallback.js +2 -2
- package/dist/core/hooks/useForkRef.d.ts +2 -2
- package/dist/core/hooks/useForkRef.js +10 -8
- package/dist/core/hooks/useLoseFocus.d.ts +1 -1
- package/dist/core/hooks/useLoseFocus.js +2 -2
- package/dist/core/hooks/useMotionPreference.d.ts +1 -1
- package/dist/core/hooks/useMotionPreference.js +2 -2
- package/dist/core/hooks/useRTL.d.ts +1 -1
- package/dist/core/hooks/useRTL.js +2 -2
- package/dist/core/hooks/useSensors.d.ts +1 -1
- package/dist/core/hooks/useSensors.js +2 -2
- package/dist/core/hooks/useThrottle.d.ts +1 -1
- package/dist/core/hooks/useThrottle.js +2 -2
- package/dist/core/modules/Carousel.d.ts +3 -2
- package/dist/core/modules/Carousel.js +25 -15
- package/dist/core/modules/Controller.d.ts +2 -2
- package/dist/core/modules/Controller.js +2 -2
- package/dist/core/modules/Core.d.ts +3 -2
- package/dist/core/modules/Core.js +5 -3
- package/dist/core/modules/Navigation.d.ts +3 -3
- package/dist/core/modules/Navigation.js +6 -4
- package/dist/core/modules/NoScroll.d.ts +3 -2
- package/dist/core/modules/NoScroll.js +7 -5
- package/dist/core/modules/Portal.d.ts +3 -2
- package/dist/core/modules/Portal.js +7 -5
- package/dist/core/modules/Toolbar.d.ts +3 -2
- package/dist/core/modules/Toolbar.js +5 -3
- package/dist/core/modules/controller/usePointerSwipe.d.ts +1 -1
- package/dist/core/modules/controller/usePointerSwipe.js +2 -2
- package/dist/core/modules/controller/usePreventSwipeNavigation.d.ts +1 -1
- package/dist/core/modules/controller/usePreventSwipeNavigation.js +4 -4
- package/dist/core/modules/controller/useWheelSwipe.d.ts +1 -1
- package/dist/core/modules/controller/useWheelSwipe.js +2 -2
- package/dist/core/utils.d.ts +2 -1
- package/dist/core/utils.js +4 -6
- package/dist/plugins/captions/CaptionsContext.d.ts +2 -3
- package/dist/plugins/captions/CaptionsContext.js +2 -2
- package/dist/plugins/captions/Description.d.ts +3 -4
- package/dist/plugins/captions/Description.js +17 -13
- package/dist/plugins/captions/Title.d.ts +3 -4
- package/dist/plugins/captions/Title.js +2 -2
- package/dist/plugins/captions/utils.d.ts +1 -1
- package/dist/plugins/captions/utils.js +3 -1
- package/dist/plugins/fullscreen/FullscreenButton.d.ts +2 -2
- package/dist/plugins/fullscreen/FullscreenButton.js +2 -2
- package/dist/plugins/fullscreen/FullscreenContext.d.ts +4 -4
- package/dist/plugins/fullscreen/FullscreenContext.js +2 -2
- package/dist/plugins/fullscreen/index.d.ts +9 -8
- package/dist/plugins/inline/Inline.js +3 -1
- package/dist/plugins/slideshow/SlideshowButton.d.ts +2 -2
- package/dist/plugins/slideshow/SlideshowButton.js +2 -2
- package/dist/plugins/slideshow/SlideshowContext.d.ts +4 -4
- package/dist/plugins/slideshow/SlideshowContext.js +2 -2
- package/dist/plugins/slideshow/index.d.ts +12 -11
- package/dist/plugins/thumbnails/Thumbnail.d.ts +3 -4
- package/dist/plugins/thumbnails/Thumbnail.js +19 -17
- package/dist/plugins/thumbnails/ThumbnailsContainer.d.ts +3 -2
- package/dist/plugins/thumbnails/ThumbnailsContainer.js +2 -2
- package/dist/plugins/thumbnails/ThumbnailsTrack.d.ts +3 -4
- package/dist/plugins/thumbnails/ThumbnailsTrack.js +8 -4
- package/dist/plugins/thumbnails/index.d.ts +9 -7
- package/dist/plugins/video/VideoSlide.d.ts +3 -4
- package/dist/plugins/video/VideoSlide.js +2 -2
- package/dist/plugins/zoom/ResponsiveImage.d.ts +5 -6
- package/dist/plugins/zoom/ResponsiveImage.js +8 -5
- package/dist/plugins/zoom/ZoomButtonsGroup.d.ts +2 -2
- package/dist/plugins/zoom/ZoomButtonsGroup.js +2 -2
- package/dist/plugins/zoom/ZoomContainer.d.ts +5 -4
- package/dist/plugins/zoom/ZoomContainer.js +11 -15
- package/dist/plugins/zoom/ZoomContext.d.ts +4 -4
- package/dist/plugins/zoom/ZoomContext.js +2 -2
- package/dist/plugins/zoom/index.d.ts +12 -13
- package/dist/styles.css +1 -0
- package/dist/types.d.ts +31 -20
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import { CLASS_FLEX_CENTER, CLASS_FULLSIZE, clsx, createIcon, cssClass, cssVar,
|
|
|
3
3
|
import { cssPrefix, cssThumbnailPrefix } from "./utils.js";
|
|
4
4
|
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
5
|
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
|
-
|
|
6
|
+
function renderThumbnail({ slide, render, rect, imageFit }) {
|
|
7
7
|
var _a;
|
|
8
8
|
const customThumbnail = (_a = render.thumbnail) === null || _a === void 0 ? void 0 : _a.call(render, { slide, render, rect, imageFit });
|
|
9
9
|
if (customThumbnail) {
|
|
@@ -21,25 +21,27 @@ const renderThumbnail = ({ slide, render, rect, imageFit }) => {
|
|
|
21
21
|
return React.createElement(ImageSlide, { slide: slide, render: render, rect: rect, imageFit: imageFit });
|
|
22
22
|
}
|
|
23
23
|
return React.createElement(UnknownThumbnailIcon, { className: thumbnailIconClass });
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
25
|
const activePrefix = makeComposePrefix("active");
|
|
26
26
|
const fadeInPrefix = makeComposePrefix("fadein");
|
|
27
27
|
const fadeOutPrefix = makeComposePrefix("fadeout");
|
|
28
28
|
const placeholderPrefix = makeComposePrefix("placeholder");
|
|
29
29
|
const DELAY = "delay";
|
|
30
30
|
const DURATION = "duration";
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
export function Thumbnail({ rect, slide, onClick, active, fadeIn, fadeOut, placeholder, render, imageFit, style, }) {
|
|
32
|
+
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
|
+
...(fadeIn
|
|
34
|
+
? {
|
|
35
|
+
[cssVar(cssThumbnailPrefix(fadeInPrefix(DURATION)))]: `${fadeIn.duration}ms`,
|
|
36
|
+
[cssVar(cssThumbnailPrefix(fadeInPrefix(DELAY)))]: `${fadeIn.delay}ms`,
|
|
37
|
+
}
|
|
38
|
+
: null),
|
|
39
|
+
...(fadeOut
|
|
40
|
+
? {
|
|
41
|
+
[cssVar(cssThumbnailPrefix(fadeOutPrefix(DURATION)))]: `${fadeOut.duration}ms`,
|
|
42
|
+
[cssVar(cssThumbnailPrefix(fadeOutPrefix(DELAY)))]: `${fadeOut.delay}ms`,
|
|
43
|
+
}
|
|
44
|
+
: null),
|
|
45
|
+
...style,
|
|
46
|
+
}, onClick: onClick }, slide && renderThumbnail({ slide, render, rect, imageFit })));
|
|
47
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ComponentProps } from "../../types.js";
|
|
2
3
|
/** Thumbnails plugin component */
|
|
3
|
-
export declare
|
|
4
|
+
export declare function ThumbnailsComponent({ thumbnails: thumbnailsProps, slides, carousel, animation, render, styles, children, }: ComponentProps): JSX.Element;
|
|
@@ -3,7 +3,7 @@ import { clsx, cssClass } from "../../core/index.js";
|
|
|
3
3
|
import { cssPrefix } from "./utils.js";
|
|
4
4
|
import { ThumbnailsTrack } from "./ThumbnailsTrack.js";
|
|
5
5
|
import { defaultThumbnailsProps } from "./Thumbnails.js";
|
|
6
|
-
export
|
|
6
|
+
export function ThumbnailsComponent({ thumbnails: thumbnailsProps, slides, carousel, animation, render, styles, children, }) {
|
|
7
7
|
const thumbnails = { ...defaultThumbnailsProps, ...thumbnailsProps };
|
|
8
8
|
const ref = React.useRef(null);
|
|
9
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 }));
|
|
@@ -11,4 +11,4 @@ export const ThumbnailsComponent = ({ thumbnails: thumbnailsProps, slides, carou
|
|
|
11
11
|
(thumbnails.position === "start" || thumbnails.position === "top") && track,
|
|
12
12
|
React.createElement("div", { className: cssClass(cssPrefix("wrapper")) }, children),
|
|
13
13
|
(thumbnails.position === "end" || thumbnails.position === "bottom") && track));
|
|
14
|
-
}
|
|
14
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { ContainerRect, DeepNonNullable, LightboxProps } from "../../types.js";
|
|
3
|
-
type ThumbnailsInternal = DeepNonNullable<LightboxProps["thumbnails"]>;
|
|
4
|
-
type ThumbnailsTrackProps = Pick<LightboxProps, "slides" | "carousel" | "animation" | "render" | "styles"> & {
|
|
3
|
+
export type ThumbnailsInternal = DeepNonNullable<LightboxProps["thumbnails"]>;
|
|
4
|
+
export type ThumbnailsTrackProps = Pick<LightboxProps, "slides" | "carousel" | "animation" | "render" | "styles"> & {
|
|
5
5
|
container: React.RefObject<HTMLDivElement>;
|
|
6
6
|
thumbnails: ThumbnailsInternal;
|
|
7
7
|
thumbnailRect: ContainerRect;
|
|
8
8
|
};
|
|
9
|
-
export declare
|
|
10
|
-
export {};
|
|
9
|
+
export declare function ThumbnailsTrack({ container, slides, carousel, render, thumbnails, thumbnailRect, styles, }: ThumbnailsTrackProps): JSX.Element;
|
|
@@ -3,9 +3,13 @@ import { ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, CLASS_FLEX_CENTER, cleanup, cls
|
|
|
3
3
|
import { cssPrefix, cssThumbnailPrefix } from "./utils.js";
|
|
4
4
|
import { Thumbnail } from "./Thumbnail.js";
|
|
5
5
|
import { defaultThumbnailsProps } from "./Thumbnails.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
function isHorizontal(position) {
|
|
7
|
+
return ["top", "bottom"].includes(position);
|
|
8
|
+
}
|
|
9
|
+
function boxSize(thumbnails, dimension, includeGap) {
|
|
10
|
+
return dimension + 2 * (thumbnails.border + thumbnails.padding) + (includeGap ? thumbnails.gap : 0);
|
|
11
|
+
}
|
|
12
|
+
export function ThumbnailsTrack({ container, slides, carousel, render, thumbnails, thumbnailRect, styles, }) {
|
|
9
13
|
const track = React.useRef(null);
|
|
10
14
|
const { globalIndex, animation } = useLightboxState().state;
|
|
11
15
|
const { publish, subscribe } = useEvents();
|
|
@@ -129,4 +133,4 @@ export const ThumbnailsTrack = ({ container, slides, carousel, render, thumbnail
|
|
|
129
133
|
return (React.createElement(Thumbnail, { key: slideIndex, rect: thumbnailRect, slide: slide, imageFit: imageFit, render: render, active: slideIndex === index, fadeIn: fadeIn, fadeOut: fadeOut, placeholder: Boolean(placeholder), onClick: handleClick(slideIndex), style: styles.thumbnail }));
|
|
130
134
|
})),
|
|
131
135
|
vignette && React.createElement("div", { className: cssClass(cssPrefix("vignette")) })));
|
|
132
|
-
}
|
|
136
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
1
|
import { Thumbnails } from "./Thumbnails.js";
|
|
3
2
|
type Position = "top" | "bottom" | "start" | "end";
|
|
4
3
|
declare module "../../types" {
|
|
@@ -25,13 +24,16 @@ declare module "../../types" {
|
|
|
25
24
|
vignette?: boolean;
|
|
26
25
|
};
|
|
27
26
|
}
|
|
27
|
+
/** `render.thumbnail` render function props */
|
|
28
|
+
type RenderThumbnailProps = {
|
|
29
|
+
slide: Slide;
|
|
30
|
+
rect: ContainerRect;
|
|
31
|
+
render: Render;
|
|
32
|
+
imageFit: ImageFit;
|
|
33
|
+
};
|
|
28
34
|
interface Render {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
rect: ContainerRect;
|
|
32
|
-
render: Render;
|
|
33
|
-
imageFit: ImageFit;
|
|
34
|
-
}) => React.ReactNode;
|
|
35
|
+
/** render custom thumbnail */
|
|
36
|
+
thumbnail?: RenderFunction<RenderThumbnailProps>;
|
|
35
37
|
}
|
|
36
38
|
interface SlotType {
|
|
37
39
|
/** thumbnail customization slot */
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { SlideVideo } from "./index.js";
|
|
3
|
-
type VideoSlideProps = {
|
|
3
|
+
export type VideoSlideProps = {
|
|
4
4
|
slide: SlideVideo;
|
|
5
5
|
offset: number;
|
|
6
6
|
};
|
|
7
7
|
/** Video slide */
|
|
8
|
-
export declare
|
|
9
|
-
export {};
|
|
8
|
+
export declare function VideoSlide({ slide, offset }: VideoSlideProps): JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, CLASS_FLEX_CENTER, clsx, cssClass, useContainerRect, useController, useEventCallback, useEvents, } from "../../core/index.js";
|
|
3
3
|
import { defaultVideoProps } from "./Video.js";
|
|
4
|
-
export
|
|
4
|
+
export function VideoSlide({ slide, offset }) {
|
|
5
5
|
const { publish } = useEvents();
|
|
6
6
|
const { setContainerRef, containerRect } = useContainerRect();
|
|
7
7
|
const videoRef = React.useRef(null);
|
|
@@ -67,4 +67,4 @@ export const VideoSlide = ({ slide, offset }) => {
|
|
|
67
67
|
}, onEnded: () => {
|
|
68
68
|
publish(ACTIVE_SLIDE_COMPLETE);
|
|
69
69
|
} }, sources.map(({ src, type }, index) => (React.createElement("source", { key: index, src: src, type: type })))))))));
|
|
70
|
-
}
|
|
70
|
+
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { ImageSlideProps } from "../../core/index.js";
|
|
3
3
|
import { ImageSource, SlideImage } from "../../types.js";
|
|
4
|
-
type ResponsiveImageSlide = Omit<SlideImage, "srcSet"> & {
|
|
4
|
+
export type ResponsiveImageSlide = Omit<SlideImage, "srcSet"> & {
|
|
5
5
|
srcSet: [ImageSource, ...ImageSource[]];
|
|
6
6
|
};
|
|
7
|
-
export declare
|
|
8
|
-
type ResponsiveImageProps = Omit<ImageSlideProps, "slide" | "rect"> & Required<Pick<ImageSlideProps, "rect">> & {
|
|
7
|
+
export declare function isResponsiveImageSlide(slide: SlideImage): slide is ResponsiveImageSlide;
|
|
8
|
+
export type ResponsiveImageProps = Omit<ImageSlideProps, "slide" | "rect"> & Required<Pick<ImageSlideProps, "rect">> & {
|
|
9
9
|
slide: ResponsiveImageSlide;
|
|
10
10
|
};
|
|
11
|
-
export declare
|
|
12
|
-
export {};
|
|
11
|
+
export declare function ResponsiveImage(props: ResponsiveImageProps): JSX.Element;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { devicePixelRatio,
|
|
3
|
-
export
|
|
4
|
-
|
|
2
|
+
import { devicePixelRatio, ImageSlide, isImageFitCover, useEventCallback, useLayoutEffect, } from "../../core/index.js";
|
|
3
|
+
export function isResponsiveImageSlide(slide) {
|
|
4
|
+
var _a;
|
|
5
|
+
return (((_a = slide.srcSet) === null || _a === void 0 ? void 0 : _a.length) || 0) > 0;
|
|
6
|
+
}
|
|
7
|
+
export function ResponsiveImage(props) {
|
|
5
8
|
var _a, _b;
|
|
6
9
|
const [state, setState] = React.useState({});
|
|
7
10
|
const { current, preload } = state;
|
|
@@ -9,7 +12,7 @@ export const ResponsiveImage = (props) => {
|
|
|
9
12
|
const srcSet = image.srcSet.sort((a, b) => a.width - b.width);
|
|
10
13
|
const width = (_a = image.width) !== null && _a !== void 0 ? _a : srcSet[srcSet.length - 1].width;
|
|
11
14
|
const height = (_b = image.height) !== null && _b !== void 0 ? _b : srcSet[srcSet.length - 1].height;
|
|
12
|
-
const cover =
|
|
15
|
+
const cover = isImageFitCover(image, imageFit);
|
|
13
16
|
const maxWidth = Math.max(...srcSet.map((x) => x.width));
|
|
14
17
|
const targetWidth = Math.min((cover ? Math.max : Math.min)(rect.width, width * (rect.height / height)), maxWidth);
|
|
15
18
|
const pixelDensity = devicePixelRatio();
|
|
@@ -44,4 +47,4 @@ export const ResponsiveImage = (props) => {
|
|
|
44
47
|
iconError: () => null,
|
|
45
48
|
} })),
|
|
46
49
|
current && (React.createElement(ImageSlide, { key: "current", ...props, slide: { ...image, src: current, srcSet: undefined }, style: style }))));
|
|
47
|
-
}
|
|
50
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { LightboxProps } from "../../types.js";
|
|
3
3
|
type ZoomButtonsGroupProps = Pick<LightboxProps, "labels" | "render">;
|
|
4
|
-
export declare
|
|
4
|
+
export declare function ZoomButtonsGroup({ labels, render }: ZoomButtonsGroupProps): JSX.Element;
|
|
5
5
|
export {};
|
|
@@ -2,7 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import { useController } from "../../core/index.js";
|
|
3
3
|
import { ZoomButton } from "./ZoomButton.js";
|
|
4
4
|
import { ACTION_ZOOM_IN, ACTION_ZOOM_OUT } from "./index.js";
|
|
5
|
-
export
|
|
5
|
+
export function ZoomButtonsGroup({ labels, render }) {
|
|
6
6
|
const zoomInRef = React.useRef(null);
|
|
7
7
|
const zoomOutRef = React.useRef(null);
|
|
8
8
|
const { transferFocus } = useController();
|
|
@@ -20,4 +20,4 @@ export const ZoomButtonsGroup = ({ labels, render }) => {
|
|
|
20
20
|
return (React.createElement(React.Fragment, null,
|
|
21
21
|
React.createElement(ZoomButton, { ref: zoomInRef, key: ACTION_ZOOM_IN, zoomIn: true, labels: labels, render: render, onLoseFocus: focusZoomOut }),
|
|
22
22
|
React.createElement(ZoomButton, { ref: zoomOutRef, key: ACTION_ZOOM_OUT, labels: labels, render: render, onLoseFocus: focusZoomIn })));
|
|
23
|
-
}
|
|
23
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { ContainerRect, LightboxProps, Slide } from "../../types.js";
|
|
3
|
-
|
|
4
|
-
export declare const ZoomContainer: React.FC<Pick<LightboxProps, "render" | "carousel" | "zoom" | "animation" | "on"> & {
|
|
3
|
+
export type ZoomContainerProps = Pick<LightboxProps, "render" | "carousel" | "zoom" | "animation" | "on"> & {
|
|
5
4
|
slide: Slide;
|
|
6
5
|
offset: number;
|
|
7
6
|
rect: ContainerRect;
|
|
8
|
-
}
|
|
7
|
+
};
|
|
8
|
+
/** Zoom container */
|
|
9
|
+
export declare function ZoomContainer({ slide, offset, rect, render, carousel, animation, zoom: originalZoomProps, on, }: ZoomContainerProps): JSX.Element | null;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { CLASS_FLEX_CENTER, CLASS_FULLSIZE, cleanup, clsx, cssClass, EVENT_ON_KEY_DOWN, EVENT_ON_POINTER_CANCEL, EVENT_ON_POINTER_DOWN, EVENT_ON_POINTER_LEAVE, EVENT_ON_POINTER_MOVE, EVENT_ON_POINTER_UP, EVENT_ON_WHEEL,
|
|
2
|
+
import { CLASS_FLEX_CENTER, CLASS_FULLSIZE, cleanup, clsx, cssClass, EVENT_ON_KEY_DOWN, EVENT_ON_POINTER_CANCEL, EVENT_ON_POINTER_DOWN, EVENT_ON_POINTER_LEAVE, EVENT_ON_POINTER_MOVE, EVENT_ON_POINTER_UP, EVENT_ON_WHEEL, ImageSlide, isImageFitCover, isImageSlide, round, useContainerRect, useController, useEventCallback, useEvents, useLayoutEffect, useLightboxState, useMotionPreference, } from "../../core/index.js";
|
|
3
3
|
import { useZoom } from "./ZoomContext.js";
|
|
4
4
|
import { defaultZoomProps } from "./Zoom.js";
|
|
5
5
|
import { ACTION_ZOOM_IN, ACTION_ZOOM_OUT } from "./index.js";
|
|
6
6
|
import { isResponsiveImageSlide, ResponsiveImage } from "./ResponsiveImage.js";
|
|
7
|
-
|
|
7
|
+
function getSlideRects(slide, cover, maxZoomPixelRatio, rect) {
|
|
8
8
|
var _a, _b;
|
|
9
9
|
let slideRect = { width: 0, height: 0 };
|
|
10
10
|
let maxSlideRect = { width: 0, height: 0 };
|
|
@@ -34,9 +34,11 @@ const getSlideRects = (slide, cover, maxZoomPixelRatio, rect) => {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
return { slideRect, maxSlideRect };
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
}
|
|
38
|
+
function distance(pointerA, pointerB) {
|
|
39
|
+
return ((pointerA.clientX - pointerB.clientX) ** 2 + (pointerA.clientY - pointerB.clientY) ** 2) ** 0.5;
|
|
40
|
+
}
|
|
41
|
+
export function ZoomContainer({ slide, offset, rect, render, carousel, animation, zoom: originalZoomProps, on, }) {
|
|
40
42
|
var _a;
|
|
41
43
|
const zoomProps = { ...defaultZoomProps, ...originalZoomProps };
|
|
42
44
|
const { currentIndex } = useLightboxState().state;
|
|
@@ -54,7 +56,7 @@ export const ZoomContainer = ({ slide, offset, rect, render, carousel, animation
|
|
|
54
56
|
const { subscribeSensors, containerRef: controllerRef, containerRect: controllerRect } = useController();
|
|
55
57
|
const { subscribe } = useEvents();
|
|
56
58
|
const reduceMotion = useMotionPreference();
|
|
57
|
-
const { slideRect, maxSlideRect } = getSlideRects({ ...slide, ...imageDimensions },
|
|
59
|
+
const { slideRect, maxSlideRect } = getSlideRects({ ...slide, ...imageDimensions }, isImageSlide(slide) && isImageFitCover(slide, carousel.imageFit), zoomProps.maxZoomPixelRatio, containerRect);
|
|
58
60
|
const maxZoom = slideRect.width ? Math.max(round(maxSlideRect.width / slideRect.width, 5), 1) : 1;
|
|
59
61
|
const changeOffsets = useEventCallback((dx, dy, targetZoom) => {
|
|
60
62
|
const newZoom = targetZoom || zoom;
|
|
@@ -296,13 +298,7 @@ export const ZoomContainer = ({ slide, offset, rect, render, carousel, animation
|
|
|
296
298
|
handleZoomIn,
|
|
297
299
|
handleZoomOut,
|
|
298
300
|
]);
|
|
299
|
-
|
|
300
|
-
? {
|
|
301
|
-
width: rect.width * zoom,
|
|
302
|
-
height: rect.height * zoom,
|
|
303
|
-
}
|
|
304
|
-
: rect;
|
|
305
|
-
let rendered = (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, slide, offset, scaledRect);
|
|
301
|
+
let rendered = (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, slide, offset, rect);
|
|
306
302
|
if (!rendered && isImageSlide(slide)) {
|
|
307
303
|
const slideProps = {
|
|
308
304
|
slide,
|
|
@@ -312,9 +308,9 @@ export const ZoomContainer = ({ slide, offset, rect, render, carousel, animation
|
|
|
312
308
|
imageFit: carousel.imageFit,
|
|
313
309
|
onClick: offset === 0 ? () => { var _a; return (_a = on.click) === null || _a === void 0 ? void 0 : _a.call(on, currentIndex); } : undefined,
|
|
314
310
|
};
|
|
315
|
-
rendered = isResponsiveImageSlide(slide) ? (React.createElement(ResponsiveImage, { ...slideProps, slide: slide, rect:
|
|
311
|
+
rendered = isResponsiveImageSlide(slide) ? (React.createElement(ResponsiveImage, { ...slideProps, slide: slide, rect: offset === 0 ? { width: rect.width * zoom, height: rect.height * zoom } : rect })) : (React.createElement(ImageSlide, { onLoad: (img) => setImageDimensions({ width: img.naturalWidth, height: img.naturalHeight }), ...slideProps }));
|
|
316
312
|
}
|
|
317
313
|
return rendered ? (React.createElement("div", { ref: setContainerRef, className: clsx(cssClass(CLASS_FULLSIZE), cssClass(CLASS_FLEX_CENTER)), ...(offset === 0
|
|
318
314
|
? { style: { transform: `scale(${zoom}) translateX(${offsetX}px) translateY(${offsetY}px)` } }
|
|
319
315
|
: null) }, rendered)) : null;
|
|
320
|
-
}
|
|
316
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ComponentProps } from "../../types.js";
|
|
3
|
+
export type ZoomContextType = {
|
|
3
4
|
isMinZoom: boolean;
|
|
4
5
|
isMaxZoom: boolean;
|
|
5
6
|
isZoomSupported: boolean;
|
|
@@ -7,5 +8,4 @@ type ZoomContextType = {
|
|
|
7
8
|
setIsMaxZoom: (value: boolean) => void;
|
|
8
9
|
};
|
|
9
10
|
export declare const useZoom: () => ZoomContextType;
|
|
10
|
-
export declare
|
|
11
|
-
export {};
|
|
11
|
+
export declare function ZoomContextProvider({ slides, children }: ComponentProps): JSX.Element;
|
|
@@ -2,7 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import { isImageSlide, makeUseContext, useEventCallback, useLayoutEffect, useLightboxState } from "../../core/index.js";
|
|
3
3
|
const ZoomContext = React.createContext(null);
|
|
4
4
|
export const useZoom = makeUseContext("useZoom", "ZoomContext", ZoomContext);
|
|
5
|
-
export
|
|
5
|
+
export function ZoomContextProvider({ slides, children }) {
|
|
6
6
|
const [isMinZoom, setIsMinZoom] = React.useState(false);
|
|
7
7
|
const [isMaxZoom, setIsMaxZoom] = React.useState(false);
|
|
8
8
|
const [isZoomSupported, setIsZoomSupported] = React.useState(false);
|
|
@@ -17,4 +17,4 @@ export const ZoomContextProvider = ({ slides, children }) => {
|
|
|
17
17
|
setIsMaxZoom,
|
|
18
18
|
}), [isMinZoom, isMaxZoom, isZoomSupported]);
|
|
19
19
|
return React.createElement(ZoomContext.Provider, { value: context }, children);
|
|
20
|
-
}
|
|
20
|
+
}
|
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { LightboxProps } from "../../types.js";
|
|
3
2
|
import { Zoom } from "./Zoom.js";
|
|
4
3
|
export declare const ACTION_ZOOM_IN = "zoom-in";
|
|
5
4
|
export declare const ACTION_ZOOM_OUT = "zoom-out";
|
|
6
|
-
/** Custom zoom button render function */
|
|
7
|
-
type RenderZoomButton = ({ ref, labels, disabled, onClick, onFocus, onBlur, }: Pick<LightboxProps, "labels"> & {
|
|
8
|
-
ref: React.ForwardedRef<HTMLButtonElement>;
|
|
9
|
-
disabled: boolean;
|
|
10
|
-
onClick: () => void;
|
|
11
|
-
onFocus: () => void;
|
|
12
|
-
onBlur: () => void;
|
|
13
|
-
}) => React.ReactNode;
|
|
14
5
|
declare module "../../types" {
|
|
15
6
|
interface LightboxProps {
|
|
16
7
|
/** Zoom plugin settings */
|
|
@@ -39,15 +30,23 @@ declare module "../../types" {
|
|
|
39
30
|
/** zoom animation duration */
|
|
40
31
|
zoom?: number;
|
|
41
32
|
}
|
|
33
|
+
/** `render.buttonZoomIn` and `render.buttonZoomOut` render function props */
|
|
34
|
+
type RenderZoomButtonProps = Pick<LightboxProps, "labels"> & {
|
|
35
|
+
ref: React.ForwardedRef<HTMLButtonElement>;
|
|
36
|
+
disabled: boolean;
|
|
37
|
+
onClick: () => void;
|
|
38
|
+
onFocus: () => void;
|
|
39
|
+
onBlur: () => void;
|
|
40
|
+
};
|
|
42
41
|
interface Render {
|
|
43
42
|
/** render custom Zoom in button */
|
|
44
|
-
buttonZoomIn?:
|
|
43
|
+
buttonZoomIn?: RenderFunction<RenderZoomButtonProps>;
|
|
45
44
|
/** render custom Zoom in button */
|
|
46
|
-
buttonZoomOut?:
|
|
45
|
+
buttonZoomOut?: RenderFunction<RenderZoomButtonProps>;
|
|
47
46
|
/** render custom Zoom in icon */
|
|
48
|
-
iconZoomIn?:
|
|
47
|
+
iconZoomIn?: RenderFunction;
|
|
49
48
|
/** render custom Zoom out icon */
|
|
50
|
-
iconZoomOut?:
|
|
49
|
+
iconZoomOut?: RenderFunction;
|
|
51
50
|
}
|
|
52
51
|
interface Callbacks {
|
|
53
52
|
zoom?: (level: number) => void;
|
package/dist/styles.css
CHANGED
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
.yarl__slide {
|
|
60
60
|
flex: 1;
|
|
61
61
|
position: relative;
|
|
62
|
+
overflow: hidden;
|
|
62
63
|
padding: calc(var(--yarl__carousel_padding_px, 0) * 1px + 100 / (100 * var(--yarl__carousel_slides_count) + (var(--yarl__carousel_slides_count) - 1) * var(--yarl__carousel_spacing_percent, 0)) * var(--yarl__carousel_padding_percent, 0) * 1%);
|
|
63
64
|
}
|
|
64
65
|
[dir=rtl] .yarl__slide {
|
package/dist/types.d.ts
CHANGED
|
@@ -105,38 +105,49 @@ export interface ControllerSettings {
|
|
|
105
105
|
/** if `true`, close the lightbox when the backdrop is clicked */
|
|
106
106
|
closeOnBackdropClick: boolean;
|
|
107
107
|
}
|
|
108
|
-
/**
|
|
109
|
-
export
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
/** Render function */
|
|
109
|
+
export type RenderFunction<T = void> = (props: T) => React.ReactNode;
|
|
110
|
+
/** `render.slide` render function props */
|
|
111
|
+
export type RenderSlideProps = [
|
|
112
112
|
/** slide */
|
|
113
|
-
slide: Slide,
|
|
113
|
+
slide: Slide,
|
|
114
114
|
/** slide offset (`0` - current slide, `1` - next slide, `-1` - previous slide, etc.) */
|
|
115
|
-
offset: number,
|
|
115
|
+
offset: number,
|
|
116
116
|
/** container rect */
|
|
117
|
-
rect: ContainerRect
|
|
117
|
+
rect: ContainerRect
|
|
118
|
+
];
|
|
119
|
+
/** `render.slideHeader` render function props */
|
|
120
|
+
export type RenderSlideHeaderProps = [slide: Slide];
|
|
121
|
+
/** `render.slideFooter` render function props */
|
|
122
|
+
export type RenderSlideFooterProps = [slide: Slide];
|
|
123
|
+
/** `render.slideContainer` render function props */
|
|
124
|
+
export type RenderSlideContainerProps = [slide: Slide, children: React.ReactNode];
|
|
125
|
+
/** Custom render functions. */
|
|
126
|
+
export interface Render {
|
|
127
|
+
/** render custom slide type, or override the default image slide */
|
|
128
|
+
slide?: (...props: RenderSlideProps) => React.ReactNode;
|
|
118
129
|
/** render custom slide header */
|
|
119
|
-
slideHeader?: (
|
|
130
|
+
slideHeader?: (...props: RenderSlideHeaderProps) => React.ReactNode;
|
|
120
131
|
/** render custom slide footer */
|
|
121
|
-
slideFooter?: (
|
|
132
|
+
slideFooter?: (...props: RenderSlideFooterProps) => React.ReactNode;
|
|
122
133
|
/** render custom slide container */
|
|
123
|
-
slideContainer?: (
|
|
134
|
+
slideContainer?: (...props: RenderSlideContainerProps) => React.ReactNode;
|
|
124
135
|
/** render custom Prev icon */
|
|
125
|
-
iconPrev?:
|
|
136
|
+
iconPrev?: RenderFunction;
|
|
126
137
|
/** render custom Next icon */
|
|
127
|
-
iconNext?:
|
|
138
|
+
iconNext?: RenderFunction;
|
|
128
139
|
/** render custom Close icon */
|
|
129
|
-
iconClose?:
|
|
140
|
+
iconClose?: RenderFunction;
|
|
130
141
|
/** render custom Loading icon */
|
|
131
|
-
iconLoading?:
|
|
142
|
+
iconLoading?: RenderFunction;
|
|
132
143
|
/** render custom Error icon */
|
|
133
|
-
iconError?:
|
|
144
|
+
iconError?: RenderFunction;
|
|
134
145
|
/** render custom Prev button */
|
|
135
|
-
buttonPrev?:
|
|
146
|
+
buttonPrev?: RenderFunction;
|
|
136
147
|
/** render custom Next button */
|
|
137
|
-
buttonNext?:
|
|
148
|
+
buttonNext?: RenderFunction;
|
|
138
149
|
/** render custom Close button */
|
|
139
|
-
buttonClose?:
|
|
150
|
+
buttonClose?: RenderFunction;
|
|
140
151
|
}
|
|
141
152
|
/** Lifecycle callbacks */
|
|
142
153
|
export interface Callbacks {
|
|
@@ -197,9 +208,9 @@ export interface ToolbarSettings {
|
|
|
197
208
|
buttons: ("close" | React.ReactNode)[];
|
|
198
209
|
}
|
|
199
210
|
/** Lightbox component properties */
|
|
200
|
-
export type ComponentProps = Omit<LightboxProps, "plugins"
|
|
211
|
+
export type ComponentProps = React.PropsWithChildren<Omit<LightboxProps, "plugins">>;
|
|
201
212
|
/** Lightbox component */
|
|
202
|
-
export type Component = React.ComponentType<
|
|
213
|
+
export type Component = React.ComponentType<ComponentProps>;
|
|
203
214
|
/** Lightbox module */
|
|
204
215
|
export type Module = {
|
|
205
216
|
/** module name */
|