yet-another-react-lightbox 1.13.4 → 2.0.0-rc.1
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.js +1 -1
- package/dist/core/components/IconButton.d.ts +1 -1
- package/dist/core/components/IconButton.js +3 -2
- package/dist/core/components/ImageSlide.js +15 -24
- package/dist/core/consts.d.ts +36 -0
- package/dist/core/consts.js +36 -0
- package/dist/core/contexts/Events.d.ts +5 -9
- package/dist/core/contexts/Events.js +23 -25
- package/dist/core/contexts/LightboxState.d.ts +20 -0
- package/dist/core/contexts/LightboxState.js +23 -0
- package/dist/core/contexts/Timeouts.d.ts +1 -2
- package/dist/core/contexts/Timeouts.js +26 -29
- package/dist/core/contexts/index.d.ts +1 -0
- package/dist/core/contexts/index.js +1 -0
- package/dist/core/hooks/index.d.ts +2 -1
- package/dist/core/hooks/index.js +2 -1
- package/dist/core/hooks/useEventCallback.d.ts +1 -0
- package/dist/core/hooks/useEventCallback.js +9 -0
- package/dist/core/hooks/useForkRef.d.ts +3 -0
- package/dist/core/hooks/useForkRef.js +15 -0
- package/dist/core/hooks/useMotionPreference.js +1 -2
- package/dist/core/hooks/useSensors.d.ts +4 -5
- package/dist/core/hooks/useSensors.js +9 -12
- package/dist/core/modules/Carousel.js +29 -29
- package/dist/core/modules/Controller.d.ts +3 -7
- package/dist/core/modules/Controller.js +144 -263
- package/dist/core/modules/Core.js +6 -4
- package/dist/core/modules/Navigation.js +16 -13
- package/dist/core/modules/NoScroll.js +4 -3
- package/dist/core/modules/Portal.js +51 -40
- package/dist/core/modules/Toolbar.js +6 -4
- package/dist/core/modules/controller/index.d.ts +8 -0
- package/dist/core/modules/controller/index.js +9 -0
- package/dist/core/modules/controller/useOffset.d.ts +2 -0
- package/dist/core/modules/controller/useOffset.js +10 -0
- package/dist/core/modules/controller/usePointerSwipe.d.ts +3 -0
- package/dist/core/modules/controller/usePointerSwipe.js +61 -0
- package/dist/core/modules/controller/usePreventSwipeNavigation.d.ts +3 -0
- package/dist/core/modules/controller/usePreventSwipeNavigation.js +20 -0
- package/dist/core/modules/controller/useWheelSwipe.d.ts +3 -0
- package/dist/core/modules/controller/useWheelSwipe.js +94 -0
- package/dist/core/utils.d.ts +12 -1
- package/dist/core/utils.js +14 -0
- package/dist/plugins/captions/Captions.d.ts +7 -0
- package/dist/plugins/captions/Captions.js +23 -0
- package/dist/plugins/captions/CaptionsContext.d.ts +8 -0
- package/dist/plugins/captions/CaptionsContext.js +15 -0
- package/dist/plugins/captions/Description.d.ts +5 -0
- package/dist/plugins/captions/Description.js +17 -0
- package/dist/plugins/captions/Title.d.ts +5 -0
- package/dist/plugins/captions/Title.js +9 -0
- package/dist/plugins/{captions.css → captions/captions.css} +0 -2
- package/dist/plugins/{Captions.d.ts → captions/index.d.ts} +3 -9
- package/dist/plugins/captions/index.js +2 -0
- package/dist/plugins/captions/utils.d.ts +1 -0
- package/dist/plugins/captions/utils.js +2 -0
- package/dist/plugins/fullscreen/Fullscreen.d.ts +3 -0
- package/dist/plugins/fullscreen/Fullscreen.js +17 -0
- package/dist/plugins/fullscreen/FullscreenButton.d.ts +8 -0
- package/dist/plugins/{Fullscreen.js → fullscreen/FullscreenButton.js} +16 -30
- package/dist/plugins/fullscreen/FullscreenContext.d.ts +5 -0
- package/dist/plugins/fullscreen/FullscreenContext.js +9 -0
- package/dist/plugins/{Fullscreen.d.ts → fullscreen/index.d.ts} +2 -11
- package/dist/plugins/fullscreen/index.js +2 -0
- package/dist/plugins/index.d.ts +7 -7
- package/dist/plugins/index.js +7 -7
- package/dist/plugins/inline/Inline.d.ts +3 -0
- package/dist/plugins/{Inline.js → inline/Inline.js} +5 -7
- package/dist/plugins/inline/index.d.ts +9 -0
- package/dist/plugins/inline/index.js +2 -0
- package/dist/plugins/slideshow/Slideshow.d.ts +7 -0
- package/dist/plugins/slideshow/Slideshow.js +20 -0
- package/dist/plugins/slideshow/SlideshowButton.d.ts +2 -0
- package/dist/plugins/{Slideshow.js → slideshow/SlideshowButton.js} +17 -44
- package/dist/plugins/{Slideshow.d.ts → slideshow/index.d.ts} +2 -4
- package/dist/plugins/slideshow/index.js +2 -0
- package/dist/plugins/thumbnails/Thumbnail.d.ts +21 -0
- package/dist/plugins/thumbnails/Thumbnail.js +45 -0
- package/dist/plugins/thumbnails/Thumbnails.d.ts +13 -0
- package/dist/plugins/thumbnails/Thumbnails.js +28 -0
- package/dist/plugins/thumbnails/ThumbnailsContainer.d.ts +3 -0
- package/dist/plugins/thumbnails/ThumbnailsContainer.js +14 -0
- package/dist/plugins/thumbnails/ThumbnailsTrack.d.ts +12 -0
- package/dist/plugins/thumbnails/ThumbnailsTrack.js +148 -0
- package/dist/plugins/{Thumbnails.d.ts → thumbnails/index.d.ts} +4 -16
- package/dist/plugins/thumbnails/index.js +2 -0
- package/dist/plugins/{thumbnails.css → thumbnails/thumbnails.css} +27 -37
- package/dist/plugins/thumbnails/utils.d.ts +2 -0
- package/dist/plugins/thumbnails/utils.js +4 -0
- package/dist/plugins/video/Video.d.ts +7 -0
- package/dist/plugins/video/Video.js +24 -0
- package/dist/plugins/video/VideoSlide.d.ts +9 -0
- package/dist/plugins/{Video.js → video/VideoSlide.js} +14 -39
- package/dist/plugins/{Video.d.ts → video/index.d.ts} +5 -13
- package/dist/plugins/video/index.js +2 -0
- package/dist/plugins/zoom/Zoom.d.ts +14 -0
- package/dist/plugins/zoom/Zoom.js +36 -0
- package/dist/plugins/zoom/ZoomButton.d.ts +7 -0
- package/dist/plugins/zoom/ZoomButton.js +50 -0
- package/dist/plugins/zoom/ZoomButtonsGroup.d.ts +5 -0
- package/dist/plugins/zoom/ZoomButtonsGroup.js +23 -0
- package/dist/plugins/zoom/ZoomContainer.d.ts +9 -0
- package/dist/plugins/zoom/ZoomContainer.js +303 -0
- package/dist/plugins/zoom/ZoomContext.d.ts +12 -0
- package/dist/plugins/zoom/ZoomContext.js +18 -0
- package/dist/plugins/zoom/ZoomWrapper.d.ts +3 -0
- package/dist/plugins/zoom/ZoomWrapper.js +26 -0
- package/dist/plugins/{Zoom.d.ts → zoom/index.d.ts} +5 -5
- package/dist/plugins/zoom/index.js +4 -0
- package/dist/props.d.ts +2 -0
- package/dist/props.js +31 -0
- package/dist/styles.css +28 -26
- package/dist/types.d.ts +8 -22
- package/dist/types.js +1 -30
- package/package.json +17 -17
- package/dist/core/hooks/useLatest.d.ts +0 -3
- package/dist/core/hooks/useLatest.js +0 -6
- package/dist/plugins/Captions.js +0 -58
- package/dist/plugins/Inline.d.ts +0 -15
- package/dist/plugins/Thumbnails.js +0 -243
- package/dist/plugins/Zoom.js +0 -441
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yet-another-react-lightbox",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-rc.1",
|
|
4
4
|
"description": "Modern React lightbox component",
|
|
5
5
|
"author": "Igor Danchenko",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,15 +10,15 @@
|
|
|
10
10
|
".": "./dist/index.js",
|
|
11
11
|
"./core": "./dist/core/index.js",
|
|
12
12
|
"./plugins": "./dist/plugins/index.js",
|
|
13
|
-
"./plugins/captions": "./dist/plugins/
|
|
14
|
-
"./plugins/captions.css": "./dist/plugins/captions.css",
|
|
15
|
-
"./plugins/fullscreen": "./dist/plugins/
|
|
16
|
-
"./plugins/inline": "./dist/plugins/
|
|
17
|
-
"./plugins/slideshow": "./dist/plugins/
|
|
18
|
-
"./plugins/thumbnails": "./dist/plugins/
|
|
19
|
-
"./plugins/thumbnails.css": "./dist/plugins/thumbnails.css",
|
|
20
|
-
"./plugins/video": "./dist/plugins/
|
|
21
|
-
"./plugins/zoom": "./dist/plugins/
|
|
13
|
+
"./plugins/captions": "./dist/plugins/captions/index.js",
|
|
14
|
+
"./plugins/captions.css": "./dist/plugins/captions/captions.css",
|
|
15
|
+
"./plugins/fullscreen": "./dist/plugins/fullscreen/index.js",
|
|
16
|
+
"./plugins/inline": "./dist/plugins/inline/index.js",
|
|
17
|
+
"./plugins/slideshow": "./dist/plugins/slideshow/index.js",
|
|
18
|
+
"./plugins/thumbnails": "./dist/plugins/thumbnails/index.js",
|
|
19
|
+
"./plugins/thumbnails.css": "./dist/plugins/thumbnails/thumbnails.css",
|
|
20
|
+
"./plugins/video": "./dist/plugins/video/index.js",
|
|
21
|
+
"./plugins/zoom": "./dist/plugins/zoom/index.js",
|
|
22
22
|
"./styles.css": "./dist/styles.css"
|
|
23
23
|
},
|
|
24
24
|
"types": "dist/index.d.ts",
|
|
@@ -34,25 +34,25 @@
|
|
|
34
34
|
"dist/plugins/index.d.ts"
|
|
35
35
|
],
|
|
36
36
|
"plugins/captions": [
|
|
37
|
-
"dist/plugins/
|
|
37
|
+
"dist/plugins/captions/index.d.ts"
|
|
38
38
|
],
|
|
39
39
|
"plugins/fullscreen": [
|
|
40
|
-
"dist/plugins/
|
|
40
|
+
"dist/plugins/fullscreen/index.d.ts"
|
|
41
41
|
],
|
|
42
42
|
"plugins/inline": [
|
|
43
|
-
"dist/plugins/
|
|
43
|
+
"dist/plugins/inline/index.d.ts"
|
|
44
44
|
],
|
|
45
45
|
"plugins/slideshow": [
|
|
46
|
-
"dist/plugins/
|
|
46
|
+
"dist/plugins/slideshow/index.d.ts"
|
|
47
47
|
],
|
|
48
48
|
"plugins/thumbnails": [
|
|
49
|
-
"dist/plugins/
|
|
49
|
+
"dist/plugins/thumbnails/index.d.ts"
|
|
50
50
|
],
|
|
51
51
|
"plugins/video": [
|
|
52
|
-
"dist/plugins/
|
|
52
|
+
"dist/plugins/video/index.d.ts"
|
|
53
53
|
],
|
|
54
54
|
"plugins/zoom": [
|
|
55
|
-
"dist/plugins/
|
|
55
|
+
"dist/plugins/zoom/index.d.ts"
|
|
56
56
|
]
|
|
57
57
|
}
|
|
58
58
|
},
|
package/dist/plugins/Captions.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { clsx, cssClass, cssVar, isDefined, makeUseContext } from "../core/utils.js";
|
|
3
|
-
import { useEvents } from "../core/contexts/Events.js";
|
|
4
|
-
import { createModule } from "../core/index.js";
|
|
5
|
-
const defaultTextAlign = "start";
|
|
6
|
-
const defaultMaxLines = 3;
|
|
7
|
-
const cssPrefix = (className) => cssClass(`slide_${className}`);
|
|
8
|
-
const hasTitle = (slide) => "title" in slide ? typeof slide.title === "string" : false;
|
|
9
|
-
const hasDescription = (slide) => "description" in slide ? typeof slide.description === "string" : false;
|
|
10
|
-
const CaptionsContext = React.createContext(null);
|
|
11
|
-
const useCaptions = makeUseContext("useCaptions", "CaptionsContext", CaptionsContext);
|
|
12
|
-
const Title = ({ title, styles }) => {
|
|
13
|
-
const { toolbarWidth } = useCaptions();
|
|
14
|
-
return (React.createElement("div", { style: styles.captionsTitleContainer, className: clsx(cssPrefix("captions_container"), cssPrefix("title_container")) },
|
|
15
|
-
React.createElement("div", { style: styles.captionsTitle, className: cssPrefix("title"), ...(toolbarWidth ? { style: { [cssVar("toolbar_width")]: `${toolbarWidth}px` } } : null) }, title)));
|
|
16
|
-
};
|
|
17
|
-
const Description = ({ description, align, maxLines, styles }) => (React.createElement("div", { style: styles.captionsDescriptionContainer, className: clsx(cssPrefix("captions_container"), cssPrefix("description_container")) },
|
|
18
|
-
React.createElement("div", { className: cssPrefix("description"), style: {
|
|
19
|
-
...(align !== defaultTextAlign || maxLines !== defaultMaxLines
|
|
20
|
-
? {
|
|
21
|
-
style: {
|
|
22
|
-
[cssVar("slide_description_text_align")]: align,
|
|
23
|
-
[cssVar("slide_description_max_lines")]: maxLines,
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
: null),
|
|
27
|
-
...styles.captionsDescription,
|
|
28
|
-
} }, description.split("\n").flatMap((line, index) => [...(index > 0 ? [React.createElement("br", { key: index })] : []), line]))));
|
|
29
|
-
export const CaptionsComponent = ({ children }) => {
|
|
30
|
-
const { subscribe } = useEvents();
|
|
31
|
-
const [toolbarWidth, setToolbarWidth] = React.useState();
|
|
32
|
-
React.useEffect(() => subscribe("toolbar-width", (topic, event) => {
|
|
33
|
-
if (!isDefined(event) || typeof event === "number") {
|
|
34
|
-
setToolbarWidth(event);
|
|
35
|
-
}
|
|
36
|
-
}), [subscribe]);
|
|
37
|
-
const context = React.useMemo(() => ({ toolbarWidth }), [toolbarWidth]);
|
|
38
|
-
return React.createElement(CaptionsContext.Provider, { value: context }, children);
|
|
39
|
-
};
|
|
40
|
-
export const CaptionsModule = createModule("captions", CaptionsComponent);
|
|
41
|
-
export const Captions = ({ augment, addParent }) => {
|
|
42
|
-
addParent("controller", CaptionsModule);
|
|
43
|
-
augment(({ render: { slideFooter: renderFooter, ...restRender }, captions, styles, ...restProps }) => ({
|
|
44
|
-
render: {
|
|
45
|
-
slideFooter: (slide) => {
|
|
46
|
-
var _a, _b;
|
|
47
|
-
return (React.createElement(React.Fragment, null, renderFooter === null || renderFooter === void 0 ? void 0 :
|
|
48
|
-
renderFooter(slide),
|
|
49
|
-
hasTitle(slide) && React.createElement(Title, { styles: styles, title: slide.title }),
|
|
50
|
-
hasDescription(slide) && (React.createElement(Description, { styles: styles, description: slide.description, align: (_a = captions === null || captions === void 0 ? void 0 : captions.descriptionTextAlign) !== null && _a !== void 0 ? _a : defaultTextAlign, maxLines: (_b = captions === null || captions === void 0 ? void 0 : captions.descriptionMaxLines) !== null && _b !== void 0 ? _b : defaultMaxLines }))));
|
|
51
|
-
},
|
|
52
|
-
...restRender,
|
|
53
|
-
},
|
|
54
|
-
styles,
|
|
55
|
-
...restProps,
|
|
56
|
-
}));
|
|
57
|
-
};
|
|
58
|
-
export default Captions;
|
package/dist/plugins/Inline.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { Component, Plugin } from "../types.js";
|
|
3
|
-
declare module "../types.js" {
|
|
4
|
-
interface LightboxProps {
|
|
5
|
-
/** HTML div element attributes to be passed to the Inline plugin container */
|
|
6
|
-
inline?: React.HTMLAttributes<HTMLDivElement>;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
/** Inline plugin container */
|
|
10
|
-
export declare const InlineContainer: Component;
|
|
11
|
-
/** Inline plugin module */
|
|
12
|
-
export declare const InlineModule: import("../types.js").Module;
|
|
13
|
-
/** Inline plugin */
|
|
14
|
-
export declare const Inline: Plugin;
|
|
15
|
-
export default Inline;
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { clsx, createIcon, createModule, cssClass, cssVar, ImageSlide, useEvents, useLatest, useLayoutEffect, useMotionPreference, useRTL, } from "../core/index.js";
|
|
3
|
-
const defaultThumbnailsProps = {
|
|
4
|
-
position: "bottom",
|
|
5
|
-
width: 120,
|
|
6
|
-
height: 80,
|
|
7
|
-
border: 1,
|
|
8
|
-
borderRadius: 4,
|
|
9
|
-
padding: 4,
|
|
10
|
-
gap: 16,
|
|
11
|
-
imageFit: "contain",
|
|
12
|
-
};
|
|
13
|
-
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" }));
|
|
14
|
-
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" }));
|
|
15
|
-
const cssPrefix = (value) => `thumbnails${value ? `_${value}` : ""}`;
|
|
16
|
-
const cssThumbnailPrefix = (value) => cssPrefix(`thumbnail${value ? `_${value}` : ""}`);
|
|
17
|
-
const getSlide = (slides, index) => slides[((index % slides.length) + slides.length) % slides.length];
|
|
18
|
-
const isHorizontal = (position) => ["top", "bottom"].includes(position);
|
|
19
|
-
const boxSize = (thumbnails, dimension, includeGap) => dimension + 2 * (thumbnails.border + thumbnails.padding) + (includeGap ? thumbnails.gap : 0);
|
|
20
|
-
const renderThumbnail = ({ slide, render, rect, imageFit }) => {
|
|
21
|
-
var _a;
|
|
22
|
-
const customThumbnail = (_a = render.thumbnail) === null || _a === void 0 ? void 0 : _a.call(render, { slide, render, rect, imageFit });
|
|
23
|
-
if (customThumbnail) {
|
|
24
|
-
return customThumbnail;
|
|
25
|
-
}
|
|
26
|
-
const thumbnailIconClass = cssClass(cssThumbnailPrefix("icon"));
|
|
27
|
-
if ("type" in slide) {
|
|
28
|
-
if (slide.type === "video") {
|
|
29
|
-
return (React.createElement(React.Fragment, null,
|
|
30
|
-
"poster" in slide && (React.createElement("img", { alt: "", src: slide.poster, className: clsx(cssClass("fullsize"), cssClass(cssPrefix("contain_image"))) })),
|
|
31
|
-
React.createElement(VideoThumbnailIcon, { className: thumbnailIconClass })));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else if ("src" in slide) {
|
|
35
|
-
return React.createElement(ImageSlide, { slide: slide, render: render, rect: rect, imageFit: imageFit });
|
|
36
|
-
}
|
|
37
|
-
return React.createElement(UnknownThumbnailIcon, { className: thumbnailIconClass });
|
|
38
|
-
};
|
|
39
|
-
const Thumbnail = ({ rect, slide, onClick, active, fadeIn, fadeOut, placeholder, render, imageFit, style, }) => (React.createElement("button", { type: "button", className: clsx(cssClass("flex_center"), cssClass(cssThumbnailPrefix()), active && cssClass(cssThumbnailPrefix("active")), fadeIn && cssClass(cssThumbnailPrefix("fadein")), fadeOut && cssClass(cssThumbnailPrefix("fadeout")), placeholder && cssClass(cssThumbnailPrefix("placeholder"))), style: {
|
|
40
|
-
...(fadeIn
|
|
41
|
-
? {
|
|
42
|
-
[cssVar(cssThumbnailPrefix("fadein_duration"))]: `${fadeIn.duration}ms`,
|
|
43
|
-
[cssVar(cssThumbnailPrefix("fadein_delay"))]: `${fadeIn.delay}ms`,
|
|
44
|
-
}
|
|
45
|
-
: null),
|
|
46
|
-
...(fadeOut
|
|
47
|
-
? {
|
|
48
|
-
[cssVar(cssThumbnailPrefix("fadeout_duration"))]: `${fadeOut.duration}ms`,
|
|
49
|
-
[cssVar(cssThumbnailPrefix("fadeout_delay"))]: `${fadeOut.delay}ms`,
|
|
50
|
-
}
|
|
51
|
-
: null),
|
|
52
|
-
...style,
|
|
53
|
-
}, onClick: onClick }, slide && renderThumbnail({ slide, render, rect, imageFit })));
|
|
54
|
-
export const ThumbnailsTrack = ({ container, startingIndex, slides, carousel, animation, render, thumbnails, thumbnailRect, styles, }) => {
|
|
55
|
-
const track = React.useRef(null);
|
|
56
|
-
const [state, setState] = React.useState({
|
|
57
|
-
index: startingIndex,
|
|
58
|
-
offset: 0,
|
|
59
|
-
});
|
|
60
|
-
const { publish, subscribe } = useEvents();
|
|
61
|
-
const reduceMotion = useLatest(useMotionPreference());
|
|
62
|
-
const isRTL = useLatest(useRTL());
|
|
63
|
-
const refs = React.useRef({
|
|
64
|
-
state,
|
|
65
|
-
thumbnails,
|
|
66
|
-
carousel,
|
|
67
|
-
animation,
|
|
68
|
-
animationOffset: 0,
|
|
69
|
-
});
|
|
70
|
-
refs.current.state = state;
|
|
71
|
-
refs.current.thumbnails = thumbnails;
|
|
72
|
-
refs.current.carousel = carousel;
|
|
73
|
-
refs.current.animation = animation;
|
|
74
|
-
const animationRef = React.useRef();
|
|
75
|
-
React.useEffect(() => subscribe("controller-swipe", (_, event) => {
|
|
76
|
-
if (event && typeof event === "object" && "globalIndex" in event) {
|
|
77
|
-
const { current } = refs;
|
|
78
|
-
if (container.current && track.current) {
|
|
79
|
-
const containerRect = container.current.getBoundingClientRect();
|
|
80
|
-
const trackRect = track.current.getBoundingClientRect();
|
|
81
|
-
current.animationOffset = isHorizontal(refs.current.thumbnails.position)
|
|
82
|
-
? trackRect.left - (containerRect.width - trackRect.width) / 2
|
|
83
|
-
: trackRect.top - (containerRect.height - trackRect.height) / 2;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
current.animationOffset = 0;
|
|
87
|
-
}
|
|
88
|
-
current.animationOverride =
|
|
89
|
-
"animationDuration" in event
|
|
90
|
-
? event.animationDuration
|
|
91
|
-
: undefined;
|
|
92
|
-
const newIndex = event.globalIndex;
|
|
93
|
-
setState({
|
|
94
|
-
index: newIndex,
|
|
95
|
-
offset: newIndex - current.state.index,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}), [container, subscribe]);
|
|
99
|
-
useLayoutEffect(() => {
|
|
100
|
-
var _a, _b, _c, _d;
|
|
101
|
-
if (track.current && state.offset) {
|
|
102
|
-
const { current } = refs;
|
|
103
|
-
(_a = animationRef.current) === null || _a === void 0 ? void 0 : _a.cancel();
|
|
104
|
-
const animationDuration = (_b = current.animationOverride) !== null && _b !== void 0 ? _b : current.animation.swipe;
|
|
105
|
-
animationRef.current = (_d = (_c = track.current).animate) === null || _d === void 0 ? void 0 : _d.call(_c, isHorizontal(current.thumbnails.position)
|
|
106
|
-
? [
|
|
107
|
-
{
|
|
108
|
-
transform: `translate3d(${(isRTL.current ? -1 : 1) *
|
|
109
|
-
boxSize(current.thumbnails, current.thumbnails.width, true) *
|
|
110
|
-
state.offset +
|
|
111
|
-
current.animationOffset}px, 0, 0)`,
|
|
112
|
-
},
|
|
113
|
-
{ transform: "translate3d(0, 0, 0)" },
|
|
114
|
-
]
|
|
115
|
-
: [
|
|
116
|
-
{
|
|
117
|
-
transform: `translate3d(0, ${boxSize(current.thumbnails, current.thumbnails.height, true) * state.offset +
|
|
118
|
-
current.animationOffset}px, 0)`,
|
|
119
|
-
},
|
|
120
|
-
{ transform: "translate3d(0, 0, 0)" },
|
|
121
|
-
], reduceMotion.current ? 0 : animationDuration);
|
|
122
|
-
if (animationRef.current) {
|
|
123
|
-
animationRef.current.onfinish = () => {
|
|
124
|
-
animationRef.current = undefined;
|
|
125
|
-
if (refs.current.state.index === state.index) {
|
|
126
|
-
setState({ index: state.index, offset: 0 });
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
current.animationOffset = 0;
|
|
131
|
-
}
|
|
132
|
-
}, [state.index, state.offset, isRTL, reduceMotion]);
|
|
133
|
-
const { index, offset } = state;
|
|
134
|
-
const { finite, preload } = carousel;
|
|
135
|
-
const items = [];
|
|
136
|
-
if (slides.length > 0) {
|
|
137
|
-
if (offset < 0) {
|
|
138
|
-
for (let i = index - preload + offset; i < index - preload; i += 1) {
|
|
139
|
-
items.push({ slide: null, index: i, placeholder: true });
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
for (let i = index - preload - (offset > 0 ? offset : 0); i < index; i += 1) {
|
|
143
|
-
if (!(finite && i < 0)) {
|
|
144
|
-
items.push({ slide: getSlide(slides, i), index: i });
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
items.push({ slide: null, index: i, placeholder: true });
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
items.push({ slide: getSlide(slides, index), index });
|
|
151
|
-
for (let i = index + 1; i <= index + preload - (offset < 0 ? offset : 0); i += 1) {
|
|
152
|
-
if (!finite || i <= slides.length - 1) {
|
|
153
|
-
items.push({ slide: getSlide(slides, i), index: i });
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
items.push({ slide: null, index: i, placeholder: true });
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (offset > 0) {
|
|
160
|
-
for (let i = index + preload + 1; i <= index + preload + offset; i += 1) {
|
|
161
|
-
items.push({ slide: null, index: i, placeholder: true });
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
const handleClick = (slideIndex) => () => {
|
|
166
|
-
if (slideIndex > index) {
|
|
167
|
-
publish("next", slideIndex - index);
|
|
168
|
-
}
|
|
169
|
-
else if (slideIndex < index) {
|
|
170
|
-
publish("prev", index - slideIndex);
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
const { width, height, border, borderRadius, padding, gap, imageFit } = thumbnails;
|
|
174
|
-
return (React.createElement("div", { className: clsx(cssClass(cssPrefix("container")), cssClass("flex_center")), style: {
|
|
175
|
-
...(width !== defaultThumbnailsProps.width
|
|
176
|
-
? { [cssVar(cssThumbnailPrefix("width"))]: `${boxSize(thumbnails, width)}px` }
|
|
177
|
-
: null),
|
|
178
|
-
...(height !== defaultThumbnailsProps.height
|
|
179
|
-
? { [cssVar(cssThumbnailPrefix("height"))]: `${boxSize(thumbnails, height)}px` }
|
|
180
|
-
: null),
|
|
181
|
-
...(border !== defaultThumbnailsProps.border
|
|
182
|
-
? { [cssVar(cssThumbnailPrefix("border"))]: `${border}px` }
|
|
183
|
-
: null),
|
|
184
|
-
...(borderRadius !== defaultThumbnailsProps.borderRadius
|
|
185
|
-
? { [cssVar(cssThumbnailPrefix("border_radius"))]: `${borderRadius}px` }
|
|
186
|
-
: null),
|
|
187
|
-
...(padding !== defaultThumbnailsProps.padding
|
|
188
|
-
? { [cssVar(cssThumbnailPrefix("padding"))]: `${padding}px` }
|
|
189
|
-
: null),
|
|
190
|
-
...(gap !== defaultThumbnailsProps.gap ? { [cssVar(cssThumbnailPrefix("gap"))]: `${gap}px` } : null),
|
|
191
|
-
...styles.thumbnailsContainer,
|
|
192
|
-
} },
|
|
193
|
-
React.createElement("nav", { ref: track, style: styles.thumbnailsTrack, className: cssClass(cssPrefix("track")) }, items.map(({ slide, index: slideIndex, placeholder }) => {
|
|
194
|
-
var _a;
|
|
195
|
-
const fadeAnimationDuration = ((_a = refs.current.animationOverride) !== null && _a !== void 0 ? _a : animation.swipe) / Math.abs(offset || 1);
|
|
196
|
-
const fadeIn = (offset > 0 && slideIndex > index + preload - offset && slideIndex <= index + preload) ||
|
|
197
|
-
(offset < 0 && slideIndex < index - preload - offset && slideIndex >= index - preload)
|
|
198
|
-
? {
|
|
199
|
-
duration: fadeAnimationDuration,
|
|
200
|
-
delay: ((offset > 0
|
|
201
|
-
? slideIndex - (index + preload - offset)
|
|
202
|
-
: index - preload - offset - slideIndex) -
|
|
203
|
-
1) *
|
|
204
|
-
fadeAnimationDuration,
|
|
205
|
-
}
|
|
206
|
-
: undefined;
|
|
207
|
-
const fadeOut = (offset > 0 && slideIndex < index - preload) || (offset < 0 && slideIndex > index + preload)
|
|
208
|
-
? {
|
|
209
|
-
duration: fadeAnimationDuration,
|
|
210
|
-
delay: (offset > 0
|
|
211
|
-
? offset - (index - preload - slideIndex)
|
|
212
|
-
: -offset - (slideIndex - (index + preload))) * fadeAnimationDuration,
|
|
213
|
-
}
|
|
214
|
-
: undefined;
|
|
215
|
-
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 }));
|
|
216
|
-
}))));
|
|
217
|
-
};
|
|
218
|
-
export const ThumbnailsComponent = ({ thumbnails: thumbnailsProps, slides, index, carousel, animation, render, styles, children, }) => {
|
|
219
|
-
const thumbnails = { ...defaultThumbnailsProps, ...thumbnailsProps };
|
|
220
|
-
const ref = React.useRef(null);
|
|
221
|
-
const track = (React.createElement(ThumbnailsTrack, { container: ref, slides: slides, thumbnails: thumbnails, carousel: carousel, animation: animation, render: render, startingIndex: index, thumbnailRect: { width: thumbnails.width, height: thumbnails.height }, styles: styles }));
|
|
222
|
-
return (React.createElement("div", { ref: ref, className: clsx(cssClass(cssPrefix()), cssClass(cssPrefix(`${thumbnails.position}`)), cssClass("fullsize")) },
|
|
223
|
-
(thumbnails.position === "start" || thumbnails.position === "top") && track,
|
|
224
|
-
React.createElement("div", { className: cssClass(cssPrefix("wrapper")) }, children),
|
|
225
|
-
(thumbnails.position === "end" || thumbnails.position === "bottom") && track));
|
|
226
|
-
};
|
|
227
|
-
export const Thumbnails = ({ augment, contains, append, addParent }) => {
|
|
228
|
-
augment(({ thumbnails, ...restProps }) => ({
|
|
229
|
-
thumbnails: {
|
|
230
|
-
...defaultThumbnailsProps,
|
|
231
|
-
...thumbnails,
|
|
232
|
-
},
|
|
233
|
-
...restProps,
|
|
234
|
-
}));
|
|
235
|
-
const module = createModule("thumbnails", ThumbnailsComponent);
|
|
236
|
-
if (contains("fullscreen")) {
|
|
237
|
-
append("fullscreen", module);
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
addParent("controller", module);
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
export default Thumbnails;
|