yet-another-react-lightbox 2.4.1 → 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 },
@@ -4,4 +4,4 @@ export type IconButtonProps = Omit<React.DetailedHTMLProps<React.ButtonHTMLAttri
4
4
  icon: React.ElementType;
5
5
  renderIcon?: () => React.ReactNode;
6
6
  };
7
- export declare const IconButton: React.ForwardRefExoticComponent<Pick<IconButtonProps, "icon" | "hidden" | "color" | "style" | "translate" | "disabled" | "className" | "placeholder" | "onPointerDown" | "onPointerMove" | "onPointerUp" | "onPointerLeave" | "onPointerCancel" | "onKeyDown" | "onKeyUp" | "onWheel" | "value" | "children" | "form" | "label" | "slot" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "id" | "lang" | "nonce" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDownCapture" | "onPointerMoveCapture" | "onPointerUpCapture" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "autoFocus" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "renderIcon"> & React.RefAttributes<HTMLButtonElement>>;
7
+ export declare const IconButton: React.ForwardRefExoticComponent<Omit<IconButtonProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
@@ -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
  };
@@ -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 === null || plugins === void 0 ? void 0 : plugins.forEach((plugin) => {
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: currentMaxSlideRect } = getSlideRects({ ...slide, ...imageDimensions }, carousel.imageFit === "cover" || ("imageFit" in slide && slide.imageFit === "cover"), zoomProps.maxZoomPixelRatio, containerRect);
58
- const maxZoom = slideRect.width ? Math.max(round(currentMaxSlideRect.width / slideRect.width, 5), 1) : 1;
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);
package/dist/styles.css CHANGED
@@ -7,7 +7,10 @@
7
7
  }
8
8
  .yarl__portal {
9
9
  position: fixed;
10
- inset: 0;
10
+ top: 0;
11
+ right: 0;
12
+ bottom: 0;
13
+ left: 0;
11
14
  opacity: 0;
12
15
  overflow: hidden;
13
16
  z-index: var(--yarl__portal_zindex, 9999);
@@ -18,7 +21,10 @@
18
21
  }
19
22
  .yarl__container {
20
23
  position: absolute;
21
- inset: 0;
24
+ top: 0;
25
+ right: 0;
26
+ bottom: 0;
27
+ left: 0;
22
28
  overflow: hidden;
23
29
  background-color: var(--yarl__container_background_color, var(--yarl__color_backdrop, #000));
24
30
  outline: 0;
@@ -150,13 +156,19 @@
150
156
  }
151
157
  .yarl__toolbar {
152
158
  position: absolute;
153
- inset: 0 0 auto auto;
159
+ top: 0;
160
+ right: 0;
161
+ bottom: auto;
162
+ left: auto;
154
163
  display: flex;
155
164
  justify-content: flex-end;
156
165
  padding: var(--yarl__toolbar_padding, 8px);
157
166
  }
158
167
  [dir=rtl] .yarl__toolbar {
159
- inset: 0 auto auto 0;
168
+ top: 0;
169
+ right: auto;
170
+ bottom: auto;
171
+ left: 0;
160
172
  }
161
173
  .yarl__icon {
162
174
  width: var(--yarl__icon_size, 32px);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yet-another-react-lightbox",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "description": "Modern React lightbox component",
5
5
  "author": "Igor Danchenko",
6
6
  "license": "MIT",