yet-another-react-lightbox 3.5.4 → 3.6.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/index.d.ts +240 -4
- package/dist/index.js +1317 -4
- package/dist/plugins/captions/captions.css +1 -33
- package/dist/plugins/captions/captions.css.d.ts +2 -0
- package/dist/plugins/captions/index.d.ts +8 -4
- package/dist/plugins/captions/index.js +104 -3
- package/dist/plugins/counter/counter.css +1 -16
- package/dist/plugins/counter/counter.css.d.ts +2 -0
- package/dist/plugins/counter/index.d.ts +8 -3
- package/dist/plugins/counter/index.js +18 -2
- package/dist/plugins/download/index.d.ts +6 -3
- package/dist/plugins/download/index.js +90 -3
- package/dist/plugins/fullscreen/index.d.ts +8 -4
- package/dist/plugins/fullscreen/index.js +128 -3
- package/dist/plugins/index.d.ts +9 -9
- package/dist/plugins/index.js +9 -9
- package/dist/plugins/inline/index.d.ts +8 -3
- package/dist/plugins/inline/index.js +26 -2
- package/dist/plugins/slideshow/index.d.ts +8 -4
- package/dist/plugins/slideshow/index.js +113 -3
- package/dist/plugins/thumbnails/index.d.ts +7 -4
- package/dist/plugins/thumbnails/index.js +262 -3
- package/dist/plugins/thumbnails/thumbnails.css +1 -139
- package/dist/plugins/thumbnails/thumbnails.css.d.ts +2 -0
- package/dist/plugins/video/index.d.ts +7 -2
- package/dist/plugins/video/index.js +109 -2
- package/dist/plugins/zoom/index.d.ts +7 -4
- package/dist/plugins/zoom/index.js +499 -3
- package/dist/styles.css +1 -281
- package/dist/styles.css.d.ts +2 -0
- package/dist/types.d.ts +123 -47
- package/dist/types.js +51 -1
- package/package.json +34 -10
- package/dist/Lightbox.d.ts +0 -4
- package/dist/Lightbox.js +0 -46
- package/dist/core/components/IconButton.d.ts +0 -7
- package/dist/core/components/IconButton.js +0 -8
- package/dist/core/components/Icons.d.ts +0 -29
- package/dist/core/components/Icons.js +0 -27
- package/dist/core/components/ImageSlide.d.ts +0 -13
- package/dist/core/components/ImageSlide.js +0 -68
- package/dist/core/components/index.d.ts +0 -3
- package/dist/core/components/index.js +0 -3
- package/dist/core/config.d.ts +0 -7
- package/dist/core/config.js +0 -93
- package/dist/core/consts.d.ts +0 -50
- package/dist/core/consts.js +0 -49
- package/dist/core/contexts/Events.d.ts +0 -17
- package/dist/core/contexts/Events.js +0 -29
- package/dist/core/contexts/LightboxProps.d.ts +0 -6
- package/dist/core/contexts/LightboxProps.js +0 -7
- package/dist/core/contexts/LightboxState.d.ts +0 -27
- package/dist/core/contexts/LightboxState.js +0 -49
- package/dist/core/contexts/Timeouts.d.ts +0 -8
- package/dist/core/contexts/Timeouts.js +0 -32
- package/dist/core/contexts/index.d.ts +0 -4
- package/dist/core/contexts/index.js +0 -4
- package/dist/core/hooks/index.d.ts +0 -11
- package/dist/core/hooks/index.js +0 -11
- package/dist/core/hooks/useAnimation.d.ts +0 -15
- package/dist/core/hooks/useAnimation.js +0 -57
- package/dist/core/hooks/useContainerRect.d.ts +0 -7
- package/dist/core/hooks/useContainerRect.js +0 -36
- package/dist/core/hooks/useDelay.d.ts +0 -1
- package/dist/core/hooks/useDelay.js +0 -10
- package/dist/core/hooks/useEventCallback.d.ts +0 -1
- package/dist/core/hooks/useEventCallback.js +0 -9
- package/dist/core/hooks/useForkRef.d.ts +0 -3
- package/dist/core/hooks/useForkRef.js +0 -17
- package/dist/core/hooks/useLayoutEffect.d.ts +0 -2
- package/dist/core/hooks/useLayoutEffect.js +0 -3
- package/dist/core/hooks/useLoseFocus.d.ts +0 -4
- package/dist/core/hooks/useLoseFocus.js +0 -19
- package/dist/core/hooks/useMotionPreference.d.ts +0 -1
- package/dist/core/hooks/useMotionPreference.js +0 -13
- package/dist/core/hooks/useRTL.d.ts +0 -1
- package/dist/core/hooks/useRTL.js +0 -9
- package/dist/core/hooks/useSensors.d.ts +0 -14
- package/dist/core/hooks/useSensors.js +0 -38
- package/dist/core/hooks/useThrottle.d.ts +0 -1
- package/dist/core/hooks/useThrottle.js +0 -16
- package/dist/core/index.d.ts +0 -7
- package/dist/core/index.js +0 -7
- package/dist/core/modules/Carousel.d.ts +0 -4
- package/dist/core/modules/Carousel.js +0 -72
- package/dist/core/modules/Controller.d.ts +0 -31
- package/dist/core/modules/Controller.js +0 -215
- package/dist/core/modules/Navigation.d.ts +0 -13
- package/dist/core/modules/Navigation.js +0 -35
- package/dist/core/modules/NoScroll.d.ts +0 -4
- package/dist/core/modules/NoScroll.js +0 -52
- package/dist/core/modules/Portal.d.ts +0 -4
- package/dist/core/modules/Portal.js +0 -92
- package/dist/core/modules/Root.d.ts +0 -4
- package/dist/core/modules/Root.js +0 -7
- package/dist/core/modules/Toolbar.d.ts +0 -4
- package/dist/core/modules/Toolbar.js +0 -25
- package/dist/core/modules/controller/index.d.ts +0 -8
- package/dist/core/modules/controller/index.js +0 -9
- package/dist/core/modules/controller/usePointerSwipe.d.ts +0 -2
- package/dist/core/modules/controller/usePointerSwipe.js +0 -72
- package/dist/core/modules/controller/usePreventSwipeNavigation.d.ts +0 -3
- package/dist/core/modules/controller/usePreventSwipeNavigation.js +0 -20
- package/dist/core/modules/controller/useWheelSwipe.d.ts +0 -3
- package/dist/core/modules/controller/useWheelSwipe.js +0 -92
- package/dist/core/modules/index.d.ts +0 -7
- package/dist/core/modules/index.js +0 -7
- package/dist/core/utils.d.ts +0 -36
- package/dist/core/utils.js +0 -70
- package/dist/plugins/captions/Captions.d.ts +0 -3
- package/dist/plugins/captions/Captions.js +0 -25
- package/dist/plugins/captions/CaptionsButton.d.ts +0 -2
- package/dist/plugins/captions/CaptionsButton.js +0 -16
- package/dist/plugins/captions/CaptionsContext.d.ts +0 -5
- package/dist/plugins/captions/CaptionsContext.js +0 -16
- package/dist/plugins/captions/Description.d.ts +0 -4
- package/dist/plugins/captions/Description.js +0 -27
- package/dist/plugins/captions/Title.d.ts +0 -4
- package/dist/plugins/captions/Title.js +0 -16
- package/dist/plugins/captions/props.d.ts +0 -19
- package/dist/plugins/captions/props.js +0 -14
- package/dist/plugins/captions/utils.d.ts +0 -1
- package/dist/plugins/captions/utils.js +0 -2
- package/dist/plugins/counter/Counter.d.ts +0 -5
- package/dist/plugins/counter/Counter.js +0 -14
- package/dist/plugins/download/Download.d.ts +0 -2
- package/dist/plugins/download/Download.js +0 -9
- package/dist/plugins/download/DownloadButton.d.ts +0 -2
- package/dist/plugins/download/DownloadButton.js +0 -19
- package/dist/plugins/download/FileSaver.d.ts +0 -1
- package/dist/plugins/download/FileSaver.js +0 -60
- package/dist/plugins/fullscreen/Fullscreen.d.ts +0 -3
- package/dist/plugins/fullscreen/Fullscreen.js +0 -13
- package/dist/plugins/fullscreen/FullscreenButton.d.ts +0 -3
- package/dist/plugins/fullscreen/FullscreenButton.js +0 -16
- package/dist/plugins/fullscreen/FullscreenContext.d.ts +0 -5
- package/dist/plugins/fullscreen/FullscreenContext.js +0 -93
- package/dist/plugins/fullscreen/props.d.ts +0 -10
- package/dist/plugins/fullscreen/props.js +0 -8
- package/dist/plugins/inline/Inline.d.ts +0 -3
- package/dist/plugins/inline/Inline.js +0 -18
- package/dist/plugins/inline/InlineContainer.d.ts +0 -4
- package/dist/plugins/inline/InlineContainer.js +0 -5
- package/dist/plugins/slideshow/Slideshow.d.ts +0 -3
- package/dist/plugins/slideshow/Slideshow.js +0 -13
- package/dist/plugins/slideshow/SlideshowButton.d.ts +0 -2
- package/dist/plugins/slideshow/SlideshowButton.js +0 -14
- package/dist/plugins/slideshow/SlideshowContext.d.ts +0 -5
- package/dist/plugins/slideshow/SlideshowContext.js +0 -79
- package/dist/plugins/slideshow/props.d.ts +0 -12
- package/dist/plugins/slideshow/props.js +0 -9
- package/dist/plugins/thumbnails/Thumbnail.d.ts +0 -15
- package/dist/plugins/thumbnails/Thumbnail.js +0 -51
- package/dist/plugins/thumbnails/Thumbnails.d.ts +0 -3
- package/dist/plugins/thumbnails/Thumbnails.js +0 -22
- package/dist/plugins/thumbnails/ThumbnailsButton.d.ts +0 -2
- package/dist/plugins/thumbnails/ThumbnailsButton.js +0 -16
- package/dist/plugins/thumbnails/ThumbnailsContext.d.ts +0 -6
- package/dist/plugins/thumbnails/ThumbnailsContext.js +0 -24
- package/dist/plugins/thumbnails/ThumbnailsTrack.d.ts +0 -5
- package/dist/plugins/thumbnails/ThumbnailsTrack.js +0 -141
- package/dist/plugins/thumbnails/props.d.ts +0 -40
- package/dist/plugins/thumbnails/props.js +0 -21
- package/dist/plugins/thumbnails/utils.d.ts +0 -2
- package/dist/plugins/thumbnails/utils.js +0 -4
- package/dist/plugins/video/Video.d.ts +0 -3
- package/dist/plugins/video/Video.js +0 -21
- package/dist/plugins/video/VideoSlide.d.ts +0 -8
- package/dist/plugins/video/VideoSlide.js +0 -74
- package/dist/plugins/video/props.d.ts +0 -29
- package/dist/plugins/video/props.js +0 -13
- package/dist/plugins/zoom/ResponsiveImage.d.ts +0 -11
- package/dist/plugins/zoom/ResponsiveImage.js +0 -58
- package/dist/plugins/zoom/Zoom.d.ts +0 -3
- package/dist/plugins/zoom/Zoom.js +0 -18
- package/dist/plugins/zoom/ZoomButton.d.ts +0 -8
- package/dist/plugins/zoom/ZoomButton.js +0 -27
- package/dist/plugins/zoom/ZoomButtonsGroup.d.ts +0 -2
- package/dist/plugins/zoom/ZoomButtonsGroup.js +0 -22
- package/dist/plugins/zoom/ZoomController.d.ts +0 -12
- package/dist/plugins/zoom/ZoomController.js +0 -17
- package/dist/plugins/zoom/ZoomToolbarControl.d.ts +0 -2
- package/dist/plugins/zoom/ZoomToolbarControl.js +0 -12
- package/dist/plugins/zoom/ZoomWrapper.d.ts +0 -5
- package/dist/plugins/zoom/ZoomWrapper.js +0 -36
- package/dist/plugins/zoom/hooks/index.d.ts +0 -6
- package/dist/plugins/zoom/hooks/index.js +0 -6
- package/dist/plugins/zoom/hooks/useZoomAnimation.d.ts +0 -2
- package/dist/plugins/zoom/hooks/useZoomAnimation.js +0 -39
- package/dist/plugins/zoom/hooks/useZoomCallback.d.ts +0 -1
- package/dist/plugins/zoom/hooks/useZoomCallback.js +0 -12
- package/dist/plugins/zoom/hooks/useZoomImageRect.d.ts +0 -5
- package/dist/plugins/zoom/hooks/useZoomImageRect.js +0 -41
- package/dist/plugins/zoom/hooks/useZoomProps.d.ts +0 -13
- package/dist/plugins/zoom/hooks/useZoomProps.js +0 -6
- package/dist/plugins/zoom/hooks/useZoomSensors.d.ts +0 -3
- package/dist/plugins/zoom/hooks/useZoomSensors.js +0 -154
- package/dist/plugins/zoom/hooks/useZoomState.d.ts +0 -12
- package/dist/plugins/zoom/hooks/useZoomState.js +0 -63
- package/dist/plugins/zoom/props.d.ts +0 -25
- package/dist/plugins/zoom/props.js +0 -15
- package/dist/props.d.ts +0 -2
- package/dist/props.js +0 -38
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { useEventCallback } from "../../hooks/index.js";
|
|
3
|
-
import { useTimeouts } from "../../contexts/index.js";
|
|
4
|
-
import { SwipeState } from "./index.js";
|
|
5
|
-
import { EVENT_ON_WHEEL } from "../../consts.js";
|
|
6
|
-
export function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidth, swipeAnimationDuration, onSwipeStart, onSwipeProgress, onSwipeFinish, onSwipeCancel) {
|
|
7
|
-
const offset = React.useRef(0);
|
|
8
|
-
const intent = React.useRef(0);
|
|
9
|
-
const intentCleanup = React.useRef();
|
|
10
|
-
const resetCleanup = React.useRef();
|
|
11
|
-
const wheelResidualMomentum = React.useRef(0);
|
|
12
|
-
const startTime = React.useRef(0);
|
|
13
|
-
const { setTimeout, clearTimeout } = useTimeouts();
|
|
14
|
-
const cancelSwipeIntentCleanup = React.useCallback(() => {
|
|
15
|
-
if (intentCleanup.current) {
|
|
16
|
-
clearTimeout(intentCleanup.current);
|
|
17
|
-
intentCleanup.current = undefined;
|
|
18
|
-
}
|
|
19
|
-
}, [clearTimeout]);
|
|
20
|
-
const cancelSwipeResetCleanup = React.useCallback(() => {
|
|
21
|
-
if (resetCleanup.current) {
|
|
22
|
-
clearTimeout(resetCleanup.current);
|
|
23
|
-
resetCleanup.current = undefined;
|
|
24
|
-
}
|
|
25
|
-
}, [clearTimeout]);
|
|
26
|
-
const handleCleanup = useEventCallback(() => {
|
|
27
|
-
if (swipeState !== SwipeState.SWIPE) {
|
|
28
|
-
offset.current = 0;
|
|
29
|
-
startTime.current = 0;
|
|
30
|
-
cancelSwipeIntentCleanup();
|
|
31
|
-
cancelSwipeResetCleanup();
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
React.useEffect(handleCleanup, [swipeState, handleCleanup]);
|
|
35
|
-
const handleCancelSwipe = useEventCallback((currentSwipeOffset) => {
|
|
36
|
-
resetCleanup.current = undefined;
|
|
37
|
-
if (offset.current === currentSwipeOffset) {
|
|
38
|
-
onSwipeCancel(offset.current);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
const onWheel = useEventCallback((event) => {
|
|
42
|
-
if (event.ctrlKey) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (Math.abs(event.deltaY) > Math.abs(event.deltaX)) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (!swipeState) {
|
|
49
|
-
if (Math.abs(event.deltaX) <= 1.2 * Math.abs(wheelResidualMomentum.current)) {
|
|
50
|
-
wheelResidualMomentum.current = event.deltaX;
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (!isSwipeValid(-event.deltaX)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
intent.current += event.deltaX;
|
|
57
|
-
cancelSwipeIntentCleanup();
|
|
58
|
-
if (Math.abs(intent.current) > 30) {
|
|
59
|
-
intent.current = 0;
|
|
60
|
-
wheelResidualMomentum.current = 0;
|
|
61
|
-
startTime.current = Date.now();
|
|
62
|
-
onSwipeStart();
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
const currentSwipeIntent = intent.current;
|
|
66
|
-
intentCleanup.current = setTimeout(() => {
|
|
67
|
-
intentCleanup.current = undefined;
|
|
68
|
-
if (currentSwipeIntent === intent.current) {
|
|
69
|
-
intent.current = 0;
|
|
70
|
-
}
|
|
71
|
-
}, swipeAnimationDuration);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
else if (swipeState === SwipeState.SWIPE) {
|
|
75
|
-
let newSwipeOffset = offset.current - event.deltaX;
|
|
76
|
-
newSwipeOffset = Math.min(Math.abs(newSwipeOffset), containerWidth) * Math.sign(newSwipeOffset);
|
|
77
|
-
offset.current = newSwipeOffset;
|
|
78
|
-
onSwipeProgress(newSwipeOffset);
|
|
79
|
-
cancelSwipeResetCleanup();
|
|
80
|
-
if (Math.abs(newSwipeOffset) > 0.2 * containerWidth) {
|
|
81
|
-
wheelResidualMomentum.current = event.deltaX;
|
|
82
|
-
onSwipeFinish(newSwipeOffset, Date.now() - startTime.current);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
resetCleanup.current = setTimeout(() => handleCancelSwipe(newSwipeOffset), 2 * swipeAnimationDuration);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
wheelResidualMomentum.current = event.deltaX;
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
React.useEffect(() => subscribeSensors(EVENT_ON_WHEEL, onWheel), [subscribeSensors, onWheel]);
|
|
92
|
-
}
|
package/dist/core/utils.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { ContainerRect, Labels, LengthOrPercentage, LightboxProps, Slide, SlideImage, ToolbarSettings } from "../types.js";
|
|
3
|
-
export declare const clsx: (...classes: (string | boolean | undefined)[]) => string;
|
|
4
|
-
export declare const cssClass: (name: string) => string;
|
|
5
|
-
export declare const cssVar: (name: string) => string;
|
|
6
|
-
export declare const composePrefix: (base: string, prefix?: string) => string;
|
|
7
|
-
export declare const makeComposePrefix: (base: string) => (prefix?: string) => string;
|
|
8
|
-
export declare const label: (labels: Labels | undefined, lbl: string) => string;
|
|
9
|
-
export declare const cleanup: (...cleaners: (() => void)[]) => () => void;
|
|
10
|
-
export declare const makeUseContext: <T>(name: string, contextName: string, context: React.Context<T | null>) => () => NonNullable<T>;
|
|
11
|
-
export declare const hasWindow: () => boolean;
|
|
12
|
-
export declare function round(value: number, decimals?: number): number;
|
|
13
|
-
export declare const isImageSlide: (slide: Slide) => slide is SlideImage;
|
|
14
|
-
export declare const isImageFitCover: (image: SlideImage, imageFit?: LightboxProps["carousel"]["imageFit"]) => boolean;
|
|
15
|
-
export declare function parseLengthPercentage(input: LengthOrPercentage): {
|
|
16
|
-
pixel: number;
|
|
17
|
-
percent?: undefined;
|
|
18
|
-
} | {
|
|
19
|
-
percent: number;
|
|
20
|
-
pixel?: undefined;
|
|
21
|
-
};
|
|
22
|
-
export declare function computeSlideRect(containerRect: ContainerRect, padding: LengthOrPercentage): {
|
|
23
|
-
width: number;
|
|
24
|
-
height: number;
|
|
25
|
-
};
|
|
26
|
-
export declare const devicePixelRatio: () => number;
|
|
27
|
-
export declare const getSlideIndex: (index: number, slidesCount: number) => number;
|
|
28
|
-
export declare const hasSlides: (slides: Slide[]) => slides is [Slide, ...Slide[]];
|
|
29
|
-
export declare const getSlide: (slides: [Slide, ...Slide[]], index: number) => Slide;
|
|
30
|
-
export declare const getSlideIfPresent: (slides: Slide[], index: number) => Slide | undefined;
|
|
31
|
-
export declare function addToolbarButton(toolbar: ToolbarSettings, key: string, button: React.ReactNode): ToolbarSettings;
|
|
32
|
-
export declare function stopNavigationEventsPropagation(): {
|
|
33
|
-
onPointerDown: (event: React.PointerEvent | React.KeyboardEvent | React.WheelEvent) => void;
|
|
34
|
-
onKeyDown: (event: React.PointerEvent | React.KeyboardEvent | React.WheelEvent) => void;
|
|
35
|
-
onWheel: (event: React.PointerEvent | React.KeyboardEvent | React.WheelEvent) => void;
|
|
36
|
-
};
|
package/dist/core/utils.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER } from "./consts.js";
|
|
3
|
-
export const clsx = (...classes) => [...classes].filter((cls) => Boolean(cls)).join(" ");
|
|
4
|
-
const cssPrefix = "yarl__";
|
|
5
|
-
export const cssClass = (name) => `${cssPrefix}${name}`;
|
|
6
|
-
export const cssVar = (name) => `--${cssPrefix}${name}`;
|
|
7
|
-
export const composePrefix = (base, prefix) => `${base}${prefix ? `_${prefix}` : ""}`;
|
|
8
|
-
export const makeComposePrefix = (base) => (prefix) => composePrefix(base, prefix);
|
|
9
|
-
export const label = (labels, lbl) => (labels && labels[lbl] ? labels[lbl] : lbl);
|
|
10
|
-
export const cleanup = (...cleaners) => () => {
|
|
11
|
-
cleaners.forEach((cleaner) => {
|
|
12
|
-
cleaner();
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
export const makeUseContext = (name, contextName, context) => () => {
|
|
16
|
-
const ctx = React.useContext(context);
|
|
17
|
-
if (!ctx) {
|
|
18
|
-
throw new Error(`${name} must be used within a ${contextName}.Provider`);
|
|
19
|
-
}
|
|
20
|
-
return ctx;
|
|
21
|
-
};
|
|
22
|
-
export const hasWindow = () => typeof window !== "undefined";
|
|
23
|
-
export function round(value, decimals = 0) {
|
|
24
|
-
const factor = 10 ** decimals;
|
|
25
|
-
return Math.round((value + Number.EPSILON) * factor) / factor;
|
|
26
|
-
}
|
|
27
|
-
export const isImageSlide = (slide) => slide.type === undefined || slide.type === "image";
|
|
28
|
-
export const isImageFitCover = (image, imageFit) => image.imageFit === IMAGE_FIT_COVER || (image.imageFit !== IMAGE_FIT_CONTAIN && imageFit === IMAGE_FIT_COVER);
|
|
29
|
-
export function parseLengthPercentage(input) {
|
|
30
|
-
if (typeof input === "number") {
|
|
31
|
-
return { pixel: input };
|
|
32
|
-
}
|
|
33
|
-
if (typeof input === "string") {
|
|
34
|
-
const value = parseInt(input, 10);
|
|
35
|
-
return input.endsWith("%") ? { percent: value } : { pixel: value };
|
|
36
|
-
}
|
|
37
|
-
return { pixel: 0 };
|
|
38
|
-
}
|
|
39
|
-
export function computeSlideRect(containerRect, padding) {
|
|
40
|
-
const paddingValue = parseLengthPercentage(padding);
|
|
41
|
-
const paddingPixels = paddingValue.percent !== undefined ? (containerRect.width / 100) * paddingValue.percent : paddingValue.pixel;
|
|
42
|
-
return {
|
|
43
|
-
width: Math.max(containerRect.width - 2 * paddingPixels, 0),
|
|
44
|
-
height: Math.max(containerRect.height - 2 * paddingPixels, 0),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
export const devicePixelRatio = () => (hasWindow() ? window === null || window === void 0 ? void 0 : window.devicePixelRatio : undefined) || 1;
|
|
48
|
-
export const getSlideIndex = (index, slidesCount) => slidesCount > 0 ? ((index % slidesCount) + slidesCount) % slidesCount : 0;
|
|
49
|
-
export const hasSlides = (slides) => slides.length > 0;
|
|
50
|
-
export const getSlide = (slides, index) => slides[getSlideIndex(index, slides.length)];
|
|
51
|
-
export const getSlideIfPresent = (slides, index) => hasSlides(slides) ? getSlide(slides, index) : undefined;
|
|
52
|
-
export function addToolbarButton(toolbar, key, button) {
|
|
53
|
-
if (!button)
|
|
54
|
-
return toolbar;
|
|
55
|
-
const { buttons, ...restToolbar } = toolbar;
|
|
56
|
-
const index = buttons.findIndex((item) => item === key);
|
|
57
|
-
const buttonWithKey = React.isValidElement(button) ? React.cloneElement(button, { key }, null) : button;
|
|
58
|
-
if (index >= 0) {
|
|
59
|
-
const result = [...buttons];
|
|
60
|
-
result.splice(index, 1, buttonWithKey);
|
|
61
|
-
return { buttons: result, ...restToolbar };
|
|
62
|
-
}
|
|
63
|
-
return { buttons: [buttonWithKey, ...buttons], ...restToolbar };
|
|
64
|
-
}
|
|
65
|
-
export function stopNavigationEventsPropagation() {
|
|
66
|
-
const stopPropagation = (event) => {
|
|
67
|
-
event.stopPropagation();
|
|
68
|
-
};
|
|
69
|
-
return { onPointerDown: stopPropagation, onKeyDown: stopPropagation, onWheel: stopPropagation };
|
|
70
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { addToolbarButton, createModule, PLUGIN_CAPTIONS } from "../../core/index.js";
|
|
3
|
-
import { Title } from "./Title.js";
|
|
4
|
-
import { Description } from "./Description.js";
|
|
5
|
-
import { CaptionsButton } from "./CaptionsButton.js";
|
|
6
|
-
import { CaptionsContextProvider } from "./CaptionsContext.js";
|
|
7
|
-
import { resolveCaptionsProps } from "./props.js";
|
|
8
|
-
export function Captions({ augment, addModule }) {
|
|
9
|
-
augment(({ captions: captionsProps, render: { slideFooter: renderFooter, ...restRender }, toolbar, ...restProps }) => {
|
|
10
|
-
const captions = resolveCaptionsProps(captionsProps);
|
|
11
|
-
return {
|
|
12
|
-
render: {
|
|
13
|
-
slideFooter: ({ slide }) => (React.createElement(React.Fragment, null, renderFooter === null || renderFooter === void 0 ? void 0 :
|
|
14
|
-
renderFooter({ slide }),
|
|
15
|
-
slide.title && React.createElement(Title, { title: slide.title }),
|
|
16
|
-
slide.description && React.createElement(Description, { description: slide.description }))),
|
|
17
|
-
...restRender,
|
|
18
|
-
},
|
|
19
|
-
toolbar: addToolbarButton(toolbar, PLUGIN_CAPTIONS, captions.showToggle ? React.createElement(CaptionsButton, null) : null),
|
|
20
|
-
captions,
|
|
21
|
-
...restProps,
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
addModule(createModule(PLUGIN_CAPTIONS, CaptionsContextProvider));
|
|
25
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { createIcon, createIconDisabled, IconButton, useLightboxProps } from "../../core/index.js";
|
|
3
|
-
import { useCaptions } from "./CaptionsContext.js";
|
|
4
|
-
const captionsIcon = () => (React.createElement(React.Fragment, null,
|
|
5
|
-
React.createElement("path", { strokeWidth: 2, stroke: "currentColor", strokeLinejoin: "round", fill: "none", d: "M3 5l18 0l0 14l-18 0l0-14z" }),
|
|
6
|
-
React.createElement("path", { d: "M7 15h3c.55 0 1-.45 1-1v-1H9.5v.5h-2v-3h2v.5H11v-1c0-.55-.45-1-1-1H7c-.55 0-1 .45-1 1v4c0 .55.45 1 1 1zm7 0h3c.55 0 1-.45 1-1v-1h-1.5v.5h-2v-3h2v.5H18v-1c0-.55-.45-1-1-1h-3c-.55 0-1 .45-1 1v4c0 .55.45 1 1 1z" })));
|
|
7
|
-
const CaptionsVisible = createIcon("CaptionsVisible", captionsIcon());
|
|
8
|
-
const CaptionsHidden = createIconDisabled("CaptionsVisible", captionsIcon());
|
|
9
|
-
export function CaptionsButton() {
|
|
10
|
-
const { visible, show, hide } = useCaptions();
|
|
11
|
-
const { render } = useLightboxProps();
|
|
12
|
-
if (render.buttonCaptions) {
|
|
13
|
-
return React.createElement(React.Fragment, null, render.buttonCaptions({ visible, show, hide }));
|
|
14
|
-
}
|
|
15
|
-
return (React.createElement(IconButton, { label: visible ? "Hide captions" : "Show captions", icon: visible ? CaptionsVisible : CaptionsHidden, renderIcon: visible ? render.iconCaptionsVisible : render.iconCaptionsHidden, onClick: visible ? hide : show }));
|
|
16
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { CaptionsRef, ComponentProps } from "../../types.js";
|
|
3
|
-
export declare const CaptionsContext: React.Context<CaptionsRef | null>;
|
|
4
|
-
export declare const useCaptions: () => CaptionsRef;
|
|
5
|
-
export declare function CaptionsContextProvider({ captions, children }: ComponentProps): React.JSX.Element;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { makeUseContext } from "../../core/index.js";
|
|
3
|
-
import { resolveCaptionsProps } from "./props.js";
|
|
4
|
-
export const CaptionsContext = React.createContext(null);
|
|
5
|
-
export const useCaptions = makeUseContext("useCaptions", "CaptionsContext", CaptionsContext);
|
|
6
|
-
export function CaptionsContextProvider({ captions, children }) {
|
|
7
|
-
const { ref } = resolveCaptionsProps(captions);
|
|
8
|
-
const [visible, setVisible] = React.useState(true);
|
|
9
|
-
const context = React.useMemo(() => ({
|
|
10
|
-
visible,
|
|
11
|
-
show: () => setVisible(true),
|
|
12
|
-
hide: () => setVisible(false),
|
|
13
|
-
}), [visible]);
|
|
14
|
-
React.useImperativeHandle(ref, () => context, [context]);
|
|
15
|
-
return React.createElement(CaptionsContext.Provider, { value: context }, children);
|
|
16
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { clsx, cssVar, useLightboxProps } from "../../core/index.js";
|
|
3
|
-
import { cssPrefix } from "./utils.js";
|
|
4
|
-
import { defaultCaptionsProps, useCaptionsProps } from "./props.js";
|
|
5
|
-
import { useCaptions } from "./CaptionsContext.js";
|
|
6
|
-
export function Description({ description }) {
|
|
7
|
-
const { descriptionTextAlign, descriptionMaxLines } = useCaptionsProps();
|
|
8
|
-
const { styles } = useLightboxProps();
|
|
9
|
-
const { visible } = useCaptions();
|
|
10
|
-
if (!visible)
|
|
11
|
-
return null;
|
|
12
|
-
return (React.createElement("div", { style: styles.captionsDescriptionContainer, className: clsx(cssPrefix("captions_container"), cssPrefix("description_container")) },
|
|
13
|
-
React.createElement("div", { className: cssPrefix("description"), style: {
|
|
14
|
-
...(descriptionTextAlign !== defaultCaptionsProps.descriptionTextAlign ||
|
|
15
|
-
descriptionMaxLines !== defaultCaptionsProps.descriptionMaxLines
|
|
16
|
-
? {
|
|
17
|
-
[cssVar("slide_description_text_align")]: descriptionTextAlign,
|
|
18
|
-
[cssVar("slide_description_max_lines")]: descriptionMaxLines,
|
|
19
|
-
}
|
|
20
|
-
: null),
|
|
21
|
-
...styles.captionsDescription,
|
|
22
|
-
} }, typeof description === "string"
|
|
23
|
-
? description
|
|
24
|
-
.split("\n")
|
|
25
|
-
.flatMap((line, index) => [...(index > 0 ? [React.createElement("br", { key: index })] : []), line])
|
|
26
|
-
: description)));
|
|
27
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { clsx, cssVar, useController, useLightboxProps } from "../../core/index.js";
|
|
3
|
-
import { cssPrefix } from "./utils.js";
|
|
4
|
-
import { useCaptions } from "./CaptionsContext.js";
|
|
5
|
-
export function Title({ title }) {
|
|
6
|
-
const { toolbarWidth } = useController();
|
|
7
|
-
const { styles } = useLightboxProps();
|
|
8
|
-
const { visible } = useCaptions();
|
|
9
|
-
if (!visible)
|
|
10
|
-
return null;
|
|
11
|
-
return (React.createElement("div", { style: styles.captionsTitleContainer, className: clsx(cssPrefix("captions_container"), cssPrefix("title_container")) },
|
|
12
|
-
React.createElement("div", { className: cssPrefix("title"), style: {
|
|
13
|
-
...(toolbarWidth ? { [cssVar("toolbar_width")]: `${toolbarWidth}px` } : null),
|
|
14
|
-
...styles.captionsTitle,
|
|
15
|
-
} }, title)));
|
|
16
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { LightboxProps } from "../../types.js";
|
|
3
|
-
export declare const defaultCaptionsProps: {
|
|
4
|
-
descriptionTextAlign: "start";
|
|
5
|
-
descriptionMaxLines: number;
|
|
6
|
-
showToggle: boolean;
|
|
7
|
-
};
|
|
8
|
-
export declare const resolveCaptionsProps: (captions: LightboxProps["captions"]) => {
|
|
9
|
-
ref?: import("react").ForwardedRef<import("../../types.js").CaptionsRef> | undefined;
|
|
10
|
-
showToggle: boolean;
|
|
11
|
-
descriptionTextAlign: import("../../types.js").TextAlignment;
|
|
12
|
-
descriptionMaxLines: number;
|
|
13
|
-
};
|
|
14
|
-
export declare function useCaptionsProps(): {
|
|
15
|
-
ref?: import("react").ForwardedRef<import("../../types.js").CaptionsRef> | undefined;
|
|
16
|
-
showToggle: boolean;
|
|
17
|
-
descriptionTextAlign: import("../../types.js").TextAlignment;
|
|
18
|
-
descriptionMaxLines: number;
|
|
19
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useLightboxProps } from "../../core/index.js";
|
|
2
|
-
export const defaultCaptionsProps = {
|
|
3
|
-
descriptionTextAlign: "start",
|
|
4
|
-
descriptionMaxLines: 3,
|
|
5
|
-
showToggle: false,
|
|
6
|
-
};
|
|
7
|
-
export const resolveCaptionsProps = (captions) => ({
|
|
8
|
-
...defaultCaptionsProps,
|
|
9
|
-
...captions,
|
|
10
|
-
});
|
|
11
|
-
export function useCaptionsProps() {
|
|
12
|
-
const { captions } = useLightboxProps();
|
|
13
|
-
return resolveCaptionsProps(captions);
|
|
14
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const cssPrefix: (className: string) => string;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { ComponentProps, PluginProps } from "../../types.js";
|
|
3
|
-
export declare function CounterComponent({ counter: { className, ...rest } }: ComponentProps): React.JSX.Element | null;
|
|
4
|
-
/** Counter plugin */
|
|
5
|
-
export declare function Counter({ addChild }: PluginProps): void;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { clsx, createModule, cssClass, MODULE_CONTROLLER, PLUGIN_COUNTER, useLightboxState } from "../../core/index.js";
|
|
3
|
-
export function CounterComponent({ counter: { className, ...rest } = {} }) {
|
|
4
|
-
const { slides, currentIndex } = useLightboxState();
|
|
5
|
-
if (slides.length === 0)
|
|
6
|
-
return null;
|
|
7
|
-
return (React.createElement("div", { className: clsx(cssClass("counter"), className), ...rest },
|
|
8
|
-
currentIndex + 1,
|
|
9
|
-
" / ",
|
|
10
|
-
slides.length));
|
|
11
|
-
}
|
|
12
|
-
export function Counter({ addChild }) {
|
|
13
|
-
addChild(MODULE_CONTROLLER, createModule(PLUGIN_COUNTER, CounterComponent));
|
|
14
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { addToolbarButton, PLUGIN_DOWNLOAD } from "../../core/index.js";
|
|
3
|
-
import { DownloadButton } from "./DownloadButton.js";
|
|
4
|
-
export function Download({ augment }) {
|
|
5
|
-
augment(({ toolbar, ...restProps }) => ({
|
|
6
|
-
toolbar: addToolbarButton(toolbar, PLUGIN_DOWNLOAD, React.createElement(DownloadButton, null)),
|
|
7
|
-
...restProps,
|
|
8
|
-
}));
|
|
9
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { createIcon, IconButton, isImageSlide, useLightboxProps, useLightboxState } from "../../core/index.js";
|
|
3
|
-
import { saveAs } from "./FileSaver.js";
|
|
4
|
-
const DownloadIcon = createIcon("DownloadIcon", React.createElement("path", { d: "M18 15v3H6v-3H4v3c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-3h-2zm-1-4-1.41-1.41L13 12.17V4h-2v8.17L8.41 9.59 7 11l5 5 5-5z" }));
|
|
5
|
-
export function DownloadButton() {
|
|
6
|
-
const { render, on } = useLightboxProps();
|
|
7
|
-
const { currentSlide, currentIndex } = useLightboxState();
|
|
8
|
-
if (render.buttonDownload) {
|
|
9
|
-
return React.createElement(React.Fragment, null, render.buttonDownload());
|
|
10
|
-
}
|
|
11
|
-
const downloadUrl = (currentSlide === null || currentSlide === void 0 ? void 0 : currentSlide.downloadUrl) || (currentSlide && isImageSlide(currentSlide) ? currentSlide.src : undefined);
|
|
12
|
-
return (React.createElement(IconButton, { label: "Download", icon: DownloadIcon, renderIcon: render.iconDownload, disabled: !downloadUrl, onClick: () => {
|
|
13
|
-
var _a;
|
|
14
|
-
if (downloadUrl) {
|
|
15
|
-
saveAs(downloadUrl, currentSlide === null || currentSlide === void 0 ? void 0 : currentSlide.downloadFilename);
|
|
16
|
-
(_a = on.download) === null || _a === void 0 ? void 0 : _a.call(on, { index: currentIndex });
|
|
17
|
-
}
|
|
18
|
-
} }));
|
|
19
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function saveAs(source: string | Blob, name?: string): void;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
function download(url, name) {
|
|
2
|
-
const xhr = new XMLHttpRequest();
|
|
3
|
-
xhr.open("GET", url);
|
|
4
|
-
xhr.responseType = "blob";
|
|
5
|
-
xhr.onload = () => {
|
|
6
|
-
saveAs(xhr.response, name);
|
|
7
|
-
};
|
|
8
|
-
xhr.onerror = () => {
|
|
9
|
-
console.error("Failed to download file");
|
|
10
|
-
};
|
|
11
|
-
xhr.send();
|
|
12
|
-
}
|
|
13
|
-
function corsEnabled(url) {
|
|
14
|
-
const xhr = new XMLHttpRequest();
|
|
15
|
-
xhr.open("HEAD", url, false);
|
|
16
|
-
try {
|
|
17
|
-
xhr.send();
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
}
|
|
21
|
-
return xhr.status >= 200 && xhr.status <= 299;
|
|
22
|
-
}
|
|
23
|
-
function click(link) {
|
|
24
|
-
try {
|
|
25
|
-
link.dispatchEvent(new MouseEvent("click"));
|
|
26
|
-
}
|
|
27
|
-
catch (e) {
|
|
28
|
-
const event = document.createEvent("MouseEvents");
|
|
29
|
-
event.initMouseEvent("click", true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
|
|
30
|
-
link.dispatchEvent(event);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export function saveAs(source, name) {
|
|
34
|
-
const link = document.createElement("a");
|
|
35
|
-
link.rel = "noopener";
|
|
36
|
-
link.download = name || "";
|
|
37
|
-
if (!link.download) {
|
|
38
|
-
link.target = "_blank";
|
|
39
|
-
}
|
|
40
|
-
if (typeof source === "string") {
|
|
41
|
-
link.href = source;
|
|
42
|
-
if (link.origin !== window.location.origin) {
|
|
43
|
-
if (corsEnabled(link.href)) {
|
|
44
|
-
download(source, name);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
link.target = "_blank";
|
|
48
|
-
click(link);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
click(link);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
link.href = URL.createObjectURL(source);
|
|
57
|
-
setTimeout(() => URL.revokeObjectURL(link.href), 30000);
|
|
58
|
-
setTimeout(() => click(link), 0);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { addToolbarButton, createModule, MODULE_CONTROLLER, PLUGIN_FULLSCREEN, PLUGIN_THUMBNAILS, } from "../../core/index.js";
|
|
3
|
-
import { resolveFullscreenProps } from "./props.js";
|
|
4
|
-
import { FullscreenButton } from "./FullscreenButton.js";
|
|
5
|
-
import { FullscreenContextProvider } from "./FullscreenContext.js";
|
|
6
|
-
export function Fullscreen({ augment, contains, addParent }) {
|
|
7
|
-
augment(({ fullscreen, toolbar, ...restProps }) => ({
|
|
8
|
-
toolbar: addToolbarButton(toolbar, PLUGIN_FULLSCREEN, React.createElement(FullscreenButton, null)),
|
|
9
|
-
fullscreen: resolveFullscreenProps(fullscreen),
|
|
10
|
-
...restProps,
|
|
11
|
-
}));
|
|
12
|
-
addParent(contains(PLUGIN_THUMBNAILS) ? PLUGIN_THUMBNAILS : MODULE_CONTROLLER, createModule(PLUGIN_FULLSCREEN, FullscreenContextProvider));
|
|
13
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { createIcon, IconButton, useLightboxProps } from "../../core/index.js";
|
|
3
|
-
import { useFullscreen } from "./FullscreenContext.js";
|
|
4
|
-
const EnterFullscreenIcon = createIcon("EnterFullscreen", React.createElement("path", { d: "M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z" }));
|
|
5
|
-
const ExitFullscreenIcon = createIcon("ExitFullscreen", React.createElement("path", { d: "M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z" }));
|
|
6
|
-
export function FullscreenButton() {
|
|
7
|
-
var _a;
|
|
8
|
-
const { fullscreen, disabled, enter, exit } = useFullscreen();
|
|
9
|
-
const { render } = useLightboxProps();
|
|
10
|
-
if (disabled)
|
|
11
|
-
return null;
|
|
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 ? "Exit Fullscreen" : "Enter Fullscreen", icon: fullscreen ? ExitFullscreenIcon : EnterFullscreenIcon, renderIcon: fullscreen ? render.iconExitFullscreen : render.iconEnterFullscreen, onClick: fullscreen ? exit : enter }));
|
|
16
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
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): React.JSX.Element;
|