yet-another-react-lightbox 2.4.2 → 2.4.3
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
CHANGED
|
@@ -5,6 +5,11 @@ const renderNode = (node, props) => {
|
|
|
5
5
|
var _a;
|
|
6
6
|
return React.createElement(node.module.component, { key: node.module.name, ...props }, (_a = node.children) === null || _a === void 0 ? void 0 : _a.map((child) => renderNode(child, props)));
|
|
7
7
|
};
|
|
8
|
+
const fixupIndex = ({ index, slides, ...rest }) => ({
|
|
9
|
+
index: index >= 0 && index < slides.length ? index : 0,
|
|
10
|
+
slides,
|
|
11
|
+
...rest,
|
|
12
|
+
});
|
|
8
13
|
export const Lightbox = (props) => {
|
|
9
14
|
const { carousel, animation, render, toolbar, controller, on, plugins, ...restProps } = props;
|
|
10
15
|
const { carousel: defaultCarousel, animation: defaultAnimation, render: defaultRender, toolbar: defaultToolbar, controller: defaultController, on: defaultOn, ...restDefaultProps } = LightboxDefaultProps;
|
|
@@ -18,7 +23,7 @@ export const Lightbox = (props) => {
|
|
|
18
23
|
]),
|
|
19
24
|
]),
|
|
20
25
|
]),
|
|
21
|
-
], plugins);
|
|
26
|
+
], plugins, [fixupIndex]);
|
|
22
27
|
const augmentedProps = augmentation({
|
|
23
28
|
carousel: { ...defaultCarousel, ...carousel },
|
|
24
29
|
animation: { ...defaultAnimation, ...animation },
|
package/dist/core/config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Augmentation, Component, Module, Node, Plugin } from "../types.js";
|
|
2
2
|
export declare const createModule: (name: string, component: Component) => Module;
|
|
3
3
|
export declare const createNode: (module: Module, children?: Node[]) => Node;
|
|
4
|
-
export declare const withPlugins: (root: Node[], plugins?: Plugin[]) => {
|
|
4
|
+
export declare const withPlugins: (root: Node[], plugins?: Plugin[], augmentations?: Augmentation[]) => {
|
|
5
5
|
config: Node[];
|
|
6
6
|
augmentation: Augmentation;
|
|
7
7
|
};
|
package/dist/core/config.js
CHANGED
|
@@ -18,9 +18,8 @@ const traverseNode = (node, target, apply) => {
|
|
|
18
18
|
return [node];
|
|
19
19
|
};
|
|
20
20
|
const traverse = (nodes, target, apply) => nodes.flatMap((node) => { var _a; return (_a = traverseNode(node, target, apply)) !== null && _a !== void 0 ? _a : []; });
|
|
21
|
-
export const withPlugins = (root, plugins) => {
|
|
21
|
+
export const withPlugins = (root, plugins = [], augmentations = []) => {
|
|
22
22
|
let config = root;
|
|
23
|
-
const augmentations = [];
|
|
24
23
|
const contains = (target) => {
|
|
25
24
|
const nodes = [...config];
|
|
26
25
|
while (nodes.length > 0) {
|
|
@@ -70,7 +69,7 @@ export const withPlugins = (root, plugins) => {
|
|
|
70
69
|
const augment = (augmentation) => {
|
|
71
70
|
augmentations.push(augmentation);
|
|
72
71
|
};
|
|
73
|
-
plugins
|
|
72
|
+
plugins.forEach((plugin) => {
|
|
74
73
|
plugin({
|
|
75
74
|
contains,
|
|
76
75
|
addParent,
|
|
@@ -31,13 +31,12 @@ export const ResponsiveImage = (props) => {
|
|
|
31
31
|
});
|
|
32
32
|
const style = {
|
|
33
33
|
WebkitTransform: "translateZ(0)",
|
|
34
|
-
...(rect.width / rect.height < width / height
|
|
35
|
-
? {
|
|
36
|
-
width: "100%",
|
|
37
|
-
height: "auto",
|
|
38
|
-
}
|
|
39
|
-
: { width: "auto", height: "100%" }),
|
|
40
34
|
};
|
|
35
|
+
if (!cover) {
|
|
36
|
+
Object.assign(style, rect.width / rect.height < width / height
|
|
37
|
+
? { width: "100%", height: "auto" }
|
|
38
|
+
: { width: "auto", height: "100%" });
|
|
39
|
+
}
|
|
41
40
|
return (React.createElement(React.Fragment, null,
|
|
42
41
|
preload && preload !== current && (React.createElement(ImageSlide, { key: "preload", ...props, slide: { ...image, src: preload, srcSet: undefined }, style: { position: "absolute", visibility: "hidden", ...style }, onLoad: () => handlePreload(preload), render: {
|
|
43
42
|
...render,
|
|
@@ -1,5 +1,5 @@
|
|
|
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, ImageSlide, isImageSlide, round, useContainerRect, useController, useEventCallback, useEvents, useLayoutEffect, useLightboxState, useMotionPreference, } from "../../core/index.js";
|
|
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, IMAGE_FIT_COVER, ImageSlide, 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";
|
|
@@ -24,12 +24,12 @@ const getSlideRects = (slide, cover, maxZoomPixelRatio, rect) => {
|
|
|
24
24
|
};
|
|
25
25
|
slideRect = cover
|
|
26
26
|
? {
|
|
27
|
-
width: Math.min(rect.width, maxSlideRect.width),
|
|
28
|
-
height: Math.min(rect.height, maxSlideRect.height),
|
|
27
|
+
width: Math.min(rect.width, maxSlideRect.width, width),
|
|
28
|
+
height: Math.min(rect.height, maxSlideRect.height, height),
|
|
29
29
|
}
|
|
30
30
|
: {
|
|
31
|
-
width: Math.round(Math.min(rect.width, (rect.height / height) * width)),
|
|
32
|
-
height: Math.round(Math.min(rect.height, (rect.width / width) * height)),
|
|
31
|
+
width: Math.round(Math.min(rect.width, (rect.height / height) * width, width)),
|
|
32
|
+
height: Math.round(Math.min(rect.height, (rect.width / width) * height, height)),
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -54,8 +54,8 @@ export const ZoomContainer = ({ slide, offset, rect, render, carousel, animation
|
|
|
54
54
|
const { subscribeSensors, containerRef: controllerRef, containerRect: controllerRect } = useController();
|
|
55
55
|
const { subscribe } = useEvents();
|
|
56
56
|
const reduceMotion = useMotionPreference();
|
|
57
|
-
const { slideRect, maxSlideRect
|
|
58
|
-
const maxZoom = slideRect.width ? Math.max(round(
|
|
57
|
+
const { slideRect, maxSlideRect } = getSlideRects({ ...slide, ...imageDimensions }, carousel.imageFit === IMAGE_FIT_COVER || ("imageFit" in slide && slide.imageFit === IMAGE_FIT_COVER), zoomProps.maxZoomPixelRatio, containerRect);
|
|
58
|
+
const maxZoom = slideRect.width ? Math.max(round(maxSlideRect.width / slideRect.width, 5), 1) : 1;
|
|
59
59
|
const changeOffsets = useEventCallback((dx, dy, targetZoom) => {
|
|
60
60
|
const newZoom = targetZoom || zoom;
|
|
61
61
|
const newOffsetX = offsetX - (dx || 0);
|