yet-another-react-lightbox 2.6.1 → 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.
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { clsx, cssClass, hasWindow, makeComposePrefix } from "../utils.js";
|
|
2
|
+
import { clsx, cssClass, hasWindow, isImageFitCover, makeComposePrefix } from "../utils.js";
|
|
3
3
|
import { useEventCallback } from "../hooks/index.js";
|
|
4
4
|
import { useEvents, useTimeouts } from "../contexts/index.js";
|
|
5
5
|
import { ErrorIcon, LoadingIcon } from "./Icons.js";
|
|
6
|
-
import { activeSlideStatus, ELEMENT_ICON,
|
|
6
|
+
import { activeSlideStatus, ELEMENT_ICON, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, } from "../consts.js";
|
|
7
7
|
const slidePrefix = makeComposePrefix("slide");
|
|
8
8
|
const slideImagePrefix = makeComposePrefix("slide_image");
|
|
9
9
|
export function ImageSlide({ slide: image, offset, render, rect, imageFit, onClick, onLoad, style }) {
|
|
@@ -45,7 +45,7 @@ export function ImageSlide({ slide: image, offset, render, rect, imageFit, onCli
|
|
|
45
45
|
const onError = React.useCallback(() => {
|
|
46
46
|
setStatus(SLIDE_STATUS_ERROR);
|
|
47
47
|
}, []);
|
|
48
|
-
const cover =
|
|
48
|
+
const cover = isImageFitCover(image, imageFit);
|
|
49
49
|
const nonInfinite = (value, fallback) => (Number.isFinite(value) ? value : fallback);
|
|
50
50
|
const maxWidth = nonInfinite(Math.max(...((_b = (_a = image.srcSet) === null || _a === void 0 ? void 0 : _a.map((x) => x.width)) !== null && _b !== void 0 ? _b : []).concat(image.width ? [image.width] : [])), ((_c = imageRef.current) === null || _c === void 0 ? void 0 : _c.naturalWidth) || 0);
|
|
51
51
|
const maxHeight = nonInfinite(Math.max(...((_e = (_d = image.srcSet) === null || _d === void 0 ? void 0 : _d.map((x) => x.height)) !== null && _e !== void 0 ? _e : []).concat(image.height ? [image.height] : [])), ((_f = imageRef.current) === null || _f === void 0 ? void 0 : _f.naturalHeight) || 0);
|
package/dist/core/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { AnimationSettings, AnimationSpec, Labels, Slide, SlideImage } from "../types.js";
|
|
2
|
+
import { AnimationSettings, AnimationSpec, Labels, LightboxProps, Slide, SlideImage } from "../types.js";
|
|
3
3
|
export declare const clsx: (...classes: (string | boolean | undefined)[]) => string;
|
|
4
4
|
export declare const cssClass: (name: string) => string;
|
|
5
5
|
export declare const cssVar: (name: string) => string;
|
|
@@ -13,6 +13,7 @@ export declare const isDefined: <T = any>(x: T | undefined) => x is T;
|
|
|
13
13
|
export declare const isNumber: (value: any) => value is number;
|
|
14
14
|
export declare const round: (value: number, decimals?: number) => number;
|
|
15
15
|
export declare const isImageSlide: (slide: Slide) => slide is SlideImage;
|
|
16
|
+
export declare const isImageFitCover: (image: SlideImage, imageFit?: LightboxProps["carousel"]["imageFit"]) => boolean;
|
|
16
17
|
export declare const parseLengthPercentage: (input: unknown) => {
|
|
17
18
|
pixel: number;
|
|
18
19
|
percent?: undefined;
|
package/dist/core/utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { AnimationDefaultProps } from "../props.js";
|
|
3
|
+
import { IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER } from "./consts.js";
|
|
3
4
|
export const clsx = (...classes) => [...classes].filter((cls) => Boolean(cls)).join(" ");
|
|
4
5
|
const cssPrefix = "yarl__";
|
|
5
6
|
export const cssClass = (name) => `${cssPrefix}${name}`;
|
|
@@ -27,6 +28,7 @@ export const round = (value, decimals = 0) => {
|
|
|
27
28
|
return Math.round((value + Number.EPSILON) * factor) / factor;
|
|
28
29
|
};
|
|
29
30
|
export const isImageSlide = (slide) => !isDefined(slide.type) || slide.type === "image";
|
|
31
|
+
export const isImageFitCover = (image, imageFit) => image.imageFit === IMAGE_FIT_COVER || (image.imageFit !== IMAGE_FIT_CONTAIN && imageFit === IMAGE_FIT_COVER);
|
|
30
32
|
export const parseLengthPercentage = (input) => {
|
|
31
33
|
if (typeof input === "number") {
|
|
32
34
|
return { pixel: input };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { devicePixelRatio,
|
|
2
|
+
import { devicePixelRatio, ImageSlide, isImageFitCover, useEventCallback, useLayoutEffect, } from "../../core/index.js";
|
|
3
3
|
export function isResponsiveImageSlide(slide) {
|
|
4
4
|
var _a;
|
|
5
5
|
return (((_a = slide.srcSet) === null || _a === void 0 ? void 0 : _a.length) || 0) > 0;
|
|
@@ -12,7 +12,7 @@ export function ResponsiveImage(props) {
|
|
|
12
12
|
const srcSet = image.srcSet.sort((a, b) => a.width - b.width);
|
|
13
13
|
const width = (_a = image.width) !== null && _a !== void 0 ? _a : srcSet[srcSet.length - 1].width;
|
|
14
14
|
const height = (_b = image.height) !== null && _b !== void 0 ? _b : srcSet[srcSet.length - 1].height;
|
|
15
|
-
const cover =
|
|
15
|
+
const cover = isImageFitCover(image, imageFit);
|
|
16
16
|
const maxWidth = Math.max(...srcSet.map((x) => x.width));
|
|
17
17
|
const targetWidth = Math.min((cover ? Math.max : Math.min)(rect.width, width * (rect.height / height)), maxWidth);
|
|
18
18
|
const pixelDensity = devicePixelRatio();
|
|
@@ -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,
|
|
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";
|
|
@@ -56,7 +56,7 @@ export function ZoomContainer({ slide, offset, rect, render, carousel, animation
|
|
|
56
56
|
const { subscribeSensors, containerRef: controllerRef, containerRect: controllerRect } = useController();
|
|
57
57
|
const { subscribe } = useEvents();
|
|
58
58
|
const reduceMotion = useMotionPreference();
|
|
59
|
-
const { slideRect, maxSlideRect } = getSlideRects({ ...slide, ...imageDimensions },
|
|
59
|
+
const { slideRect, maxSlideRect } = getSlideRects({ ...slide, ...imageDimensions }, isImageSlide(slide) && isImageFitCover(slide, carousel.imageFit), zoomProps.maxZoomPixelRatio, containerRect);
|
|
60
60
|
const maxZoom = slideRect.width ? Math.max(round(maxSlideRect.width / slideRect.width, 5), 1) : 1;
|
|
61
61
|
const changeOffsets = useEventCallback((dx, dy, targetZoom) => {
|
|
62
62
|
const newZoom = targetZoom || zoom;
|
|
@@ -298,13 +298,7 @@ export function ZoomContainer({ slide, offset, rect, render, carousel, animation
|
|
|
298
298
|
handleZoomIn,
|
|
299
299
|
handleZoomOut,
|
|
300
300
|
]);
|
|
301
|
-
|
|
302
|
-
? {
|
|
303
|
-
width: rect.width * zoom,
|
|
304
|
-
height: rect.height * zoom,
|
|
305
|
-
}
|
|
306
|
-
: rect;
|
|
307
|
-
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);
|
|
308
302
|
if (!rendered && isImageSlide(slide)) {
|
|
309
303
|
const slideProps = {
|
|
310
304
|
slide,
|
|
@@ -314,7 +308,7 @@ export function ZoomContainer({ slide, offset, rect, render, carousel, animation
|
|
|
314
308
|
imageFit: carousel.imageFit,
|
|
315
309
|
onClick: offset === 0 ? () => { var _a; return (_a = on.click) === null || _a === void 0 ? void 0 : _a.call(on, currentIndex); } : undefined,
|
|
316
310
|
};
|
|
317
|
-
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 }));
|
|
318
312
|
}
|
|
319
313
|
return rendered ? (React.createElement("div", { ref: setContainerRef, className: clsx(cssClass(CLASS_FULLSIZE), cssClass(CLASS_FLEX_CENTER)), ...(offset === 0
|
|
320
314
|
? { style: { transform: `scale(${zoom}) translateX(${offsetX}px) translateY(${offsetY}px)` } }
|