yet-another-react-lightbox 2.0.0-rc.1 → 2.0.0-rc.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,8 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { createModule } from "../config.js";
3
- import { LightboxDefaultProps } from "../../props.js";
4
3
  import { useContainerRect } from "../hooks/index.js";
5
- import { clsx, composePrefix, cssClass, cssVar, isImageSlide, parseSpacing } from "../utils.js";
4
+ import { clsx, composePrefix, cssClass, cssVar, isImageSlide, parseLengthPercentage } from "../utils.js";
6
5
  import { ImageSlide } from "../components/index.js";
7
6
  import { useController } from "./Controller.js";
8
7
  import { useEvents } from "../contexts/Events.js";
@@ -10,7 +9,6 @@ import { useLightboxState } from "../contexts/LightboxState.js";
10
9
  import { CLASS_FLEX_CENTER, CLASS_FULLSIZE, MODULE_CAROUSEL, YARL_EVENT_BACKDROP_CLICK } from "../consts.js";
11
10
  const cssPrefix = (value) => composePrefix(MODULE_CAROUSEL, value);
12
11
  const cssSlidePrefix = (value) => composePrefix("slide", value);
13
- const sanitize = (value) => (value === 0 || value === "0" ? "0px" : value);
14
12
  const CarouselSlide = ({ slide, offset }) => {
15
13
  const { setContainerRef, containerRect, containerRef } = useContainerRect();
16
14
  const { publish } = useEvents();
@@ -45,7 +43,8 @@ const Placeholder = () => React.createElement("div", { className: cssClass("slid
45
43
  export const Carousel = ({ slides, carousel: { finite, preload, padding, spacing } }) => {
46
44
  const { state: { currentIndex, globalIndex }, } = useLightboxState();
47
45
  const { setCarouselRef } = useController();
48
- const spacingValue = parseSpacing(spacing);
46
+ const spacingValue = parseLengthPercentage(spacing);
47
+ const paddingValue = parseLengthPercentage(padding);
49
48
  const items = [];
50
49
  if ((slides === null || slides === void 0 ? void 0 : slides.length) > 0) {
51
50
  for (let i = currentIndex - preload; i < currentIndex; i += 1) {
@@ -62,9 +61,8 @@ export const Carousel = ({ slides, carousel: { finite, preload, padding, spacing
62
61
  [`${cssVar(cssPrefix("slides_count"))}`]: items.length,
63
62
  [`${cssVar(cssPrefix("spacing_px"))}`]: spacingValue.pixel || 0,
64
63
  [`${cssVar(cssPrefix("spacing_percent"))}`]: spacingValue.percent || 0,
65
- ...(padding !== LightboxDefaultProps.carousel.padding
66
- ? { [cssVar(cssPrefix("padding"))]: sanitize(padding) }
67
- : null),
64
+ [`${cssVar(cssPrefix("padding_px"))}`]: paddingValue.pixel || 0,
65
+ [`${cssVar(cssPrefix("padding_percent"))}`]: paddingValue.percent || 0,
68
66
  } }, items));
69
67
  };
70
68
  export const CarouselModule = createModule(MODULE_CAROUSEL, Carousel);
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { createModule } from "../config.js";
3
- import { cleanup, clsx, cssClass, cssVar, isNumber, makeComposePrefix, makeUseContext, parseSpacing, } from "../utils.js";
3
+ import { cleanup, clsx, cssClass, cssVar, isNumber, makeComposePrefix, makeUseContext, parseLengthPercentage, } from "../utils.js";
4
4
  import { useContainerRect, useEventCallback, useForkRef, useLayoutEffect, useMotionPreference, useRTL, useSensors, } from "../hooks/index.js";
5
5
  import { useEvents, useLightboxState, useTimeouts } from "../contexts/index.js";
6
6
  import { SwipeState, usePointerSwipe, usePreventSwipeNavigation, useWheelSwipe } from "./controller/index.js";
@@ -104,7 +104,7 @@ export const Controller = ({ children, ...props }) => {
104
104
  const swipeAnimation = carouselSwipeAnimation.current;
105
105
  carouselSwipeAnimation.current = undefined;
106
106
  if (swipeAnimation && carouselRef.current && containerRect) {
107
- const parsedSpacing = parseSpacing(carousel.spacing);
107
+ const parsedSpacing = parseLengthPercentage(carousel.spacing);
108
108
  const spacingValue = (parsedSpacing.percent ? (parsedSpacing.percent * containerRect.width) / 100 : parsedSpacing.pixel) ||
109
109
  0;
110
110
  (_a = carouselAnimation.current) === null || _a === void 0 ? void 0 : _a.cancel();
@@ -13,7 +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 parseSpacing: (spacing: unknown) => {
16
+ export declare const parseLengthPercentage: (input: unknown) => {
17
17
  pixel: number;
18
18
  percent?: undefined;
19
19
  } | {
@@ -26,13 +26,13 @@ export const round = (value, decimals = 0) => {
26
26
  return Math.round((value + Number.EPSILON) * factor) / factor;
27
27
  };
28
28
  export const isImageSlide = (slide) => !isDefined(slide.type) || slide.type === "image";
29
- export const parseSpacing = (spacing) => {
30
- if (typeof spacing === "number") {
31
- return { pixel: spacing };
29
+ export const parseLengthPercentage = (input) => {
30
+ if (typeof input === "number") {
31
+ return { pixel: input };
32
32
  }
33
- if (typeof spacing === "string") {
34
- const value = parseInt(spacing, 10);
35
- return spacing.endsWith("%") ? { percent: value } : { pixel: value };
33
+ if (typeof input === "string") {
34
+ const value = parseInt(input, 10);
35
+ return input.endsWith("%") ? { percent: value } : { pixel: value };
36
36
  }
37
37
  return { pixel: 0 };
38
38
  };
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { ACTION_CLOSE, clsx, createModule, cssClass, MODULE_NO_SCROLL, MODULE_PORTAL, PLUGIN_INLINE, } from "../../core/index.js";
3
- const InlineContainer = ({ inline: { className, ...rest } = {}, children }) => (React.createElement("div", { className: clsx(cssClass("root"), className), ...rest }, children));
3
+ const InlineContainer = ({ inline: { className, ...rest } = {}, children }) => (React.createElement("div", { className: clsx(cssClass("root"), cssClass("relative"), className), ...rest }, children));
4
4
  export const Inline = ({ augment, replace, remove }) => {
5
5
  augment(({ toolbar: { buttons, ...restToolbar }, open, close, controller: { focus, aria, touchAction, ...restController }, className, ...restProps }) => ({
6
6
  open: true,
package/dist/styles.css CHANGED
@@ -2,6 +2,9 @@
2
2
  width: 100%;
3
3
  height: 100%;
4
4
  }
5
+ .yarl__relative {
6
+ position: relative;
7
+ }
5
8
  .yarl__portal {
6
9
  position: fixed;
7
10
  inset: 0;
@@ -47,7 +50,7 @@
47
50
  .yarl__slide {
48
51
  flex: 1;
49
52
  position: relative;
50
- padding: var(--yarl__carousel_padding, 16px);
53
+ padding: calc(var(--yarl__carousel_padding_px, 0) * 1px + 100 / (100 * var(--yarl__carousel_slides_count, 0) + (var(--yarl__carousel_slides_count, 0) - 1) * var(--yarl__carousel_spacing_percent, 0)) * var(--yarl__carousel_padding_percent, 0) * 1%);
51
54
  }
52
55
  [dir=rtl] .yarl__slide {
53
56
  --yarl__direction: -1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yet-another-react-lightbox",
3
- "version": "2.0.0-rc.1",
3
+ "version": "2.0.0-rc.2",
4
4
  "description": "Modern React lightbox component",
5
5
  "author": "Igor Danchenko",
6
6
  "license": "MIT",