yet-another-react-lightbox 3.21.4 → 3.21.6

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/index.d.ts CHANGED
@@ -44,6 +44,9 @@ declare function stopNavigationEventsPropagation(): {
44
44
  onWheel: (event: React.PointerEvent | React.KeyboardEvent | React.WheelEvent) => void;
45
45
  };
46
46
  declare function calculatePreload(carousel: CarouselSettings, slides: Slide[], minimum?: number): number;
47
+ declare function makeInertWhen(condition: boolean): {
48
+ inert: string | boolean | undefined;
49
+ };
47
50
 
48
51
  declare function createModule(name: string, component: Component): Module;
49
52
  declare function createNode(module: Module, children?: Node$1[]): Node$1;
@@ -280,4 +283,4 @@ declare const RootModule: Module;
280
283
  declare function Toolbar({ toolbar: { buttons }, render: { buttonClose, iconClose }, styles }: ComponentProps): React.JSX.Element;
281
284
  declare const ToolbarModule: Module;
282
285
 
283
- export { Augmentation, Callback, Carousel, CarouselModule, CarouselSettings, CloseIcon, Component, ComponentProps, type ComputeAnimation, ContainerRect, Controller, ControllerContext, type ControllerContextType, ControllerModule, ControllerRef, ControllerSettings, DocumentContext, DocumentContextProvider, type DocumentContextProviderProps, type DocumentContextType, ErrorIcon, type Event, type EventCallback, EventTypes, EventsContext, type EventsContextType, EventsProvider, IconButton, type IconButtonProps, ImageSlide, type ImageSlideProps, type KeyboardEventType, Label, Labels, LengthOrPercentage, Lightbox, LightboxDefaultProps, LightboxDispatchContext, type LightboxDispatchContextType, LightboxExternalProps, LightboxProps, LightboxPropsContext, type LightboxPropsContextType, LightboxPropsProvider, LightboxRoot, LightboxState, type LightboxStateAction, LightboxStateContext, type LightboxStateContextType, LightboxStateProvider, type LightboxStateProviderProps, LightboxStateSwipeAction, LightboxStateUpdateAction, LoadingIcon, Module, Navigation, NavigationButton, type NavigationButtonProps, NavigationModule, NextIcon, NoScroll, NoScrollModule, Node$1 as Node, Plugin, type PointerEventType, Portal, PortalModule, PreviousIcon, type Publish, type ReactEventType, type RegisterSensors, Render, RenderFunction, Root, RootModule, type SensorCallback, Slide, SlideImage, type Subscribe, type SubscribeSensors, type SupportedEventType, SwipeState, TimeoutsContext, type TimeoutsContextType, TimeoutsProvider, Toolbar, ToolbarModule, ToolbarSettings, type Topic, type Unsubscribe, type UseSensors, type WheelEventType, addToolbarButton, calculatePreload, cleanup, clsx, composePrefix, computeSlideRect, createIcon, createIconDisabled, createModule, createNode, cssClass, cssVar, Lightbox as default, devicePixelRatio, getSlide, getSlideIfPresent, getSlideIndex, getSlideKey, hasSlides, hasWindow, isImageFitCover, isImageSlide, label, makeComposePrefix, makeUseContext, parseInt, parseLengthPercentage, round, setRef, stopNavigationEventsPropagation, useAnimation, useContainerRect, useController, useDelay, useDocumentContext, useEventCallback, useEvents, useForkRef, useKeyboardNavigation, useLayoutEffect, useLightboxDispatch, useLightboxProps, useLightboxState, useLoseFocus, useMotionPreference, useNavigationState, usePointerSwipe, usePreventWheelDefaults, useRTL, useSensors, useThrottle, useTimeouts, useWheelSwipe, withPlugins };
286
+ export { Augmentation, Callback, Carousel, CarouselModule, CarouselSettings, CloseIcon, Component, ComponentProps, type ComputeAnimation, ContainerRect, Controller, ControllerContext, type ControllerContextType, ControllerModule, ControllerRef, ControllerSettings, DocumentContext, DocumentContextProvider, type DocumentContextProviderProps, type DocumentContextType, ErrorIcon, type Event, type EventCallback, EventTypes, EventsContext, type EventsContextType, EventsProvider, IconButton, type IconButtonProps, ImageSlide, type ImageSlideProps, type KeyboardEventType, Label, Labels, LengthOrPercentage, Lightbox, LightboxDefaultProps, LightboxDispatchContext, type LightboxDispatchContextType, LightboxExternalProps, LightboxProps, LightboxPropsContext, type LightboxPropsContextType, LightboxPropsProvider, LightboxRoot, LightboxState, type LightboxStateAction, LightboxStateContext, type LightboxStateContextType, LightboxStateProvider, type LightboxStateProviderProps, LightboxStateSwipeAction, LightboxStateUpdateAction, LoadingIcon, Module, Navigation, NavigationButton, type NavigationButtonProps, NavigationModule, NextIcon, NoScroll, NoScrollModule, Node$1 as Node, Plugin, type PointerEventType, Portal, PortalModule, PreviousIcon, type Publish, type ReactEventType, type RegisterSensors, Render, RenderFunction, Root, RootModule, type SensorCallback, Slide, SlideImage, type Subscribe, type SubscribeSensors, type SupportedEventType, SwipeState, TimeoutsContext, type TimeoutsContextType, TimeoutsProvider, Toolbar, ToolbarModule, ToolbarSettings, type Topic, type Unsubscribe, type UseSensors, type WheelEventType, addToolbarButton, calculatePreload, cleanup, clsx, composePrefix, computeSlideRect, createIcon, createIconDisabled, createModule, createNode, cssClass, cssVar, Lightbox as default, devicePixelRatio, getSlide, getSlideIfPresent, getSlideIndex, getSlideKey, hasSlides, hasWindow, isImageFitCover, isImageSlide, label, makeComposePrefix, makeInertWhen, makeUseContext, parseInt, parseLengthPercentage, round, setRef, stopNavigationEventsPropagation, useAnimation, useContainerRect, useController, useDelay, useDocumentContext, useEventCallback, useEvents, useForkRef, useKeyboardNavigation, useLayoutEffect, useLightboxDispatch, useLightboxProps, useLightboxState, useLoseFocus, useMotionPreference, useNavigationState, usePointerSwipe, usePreventWheelDefaults, useRTL, useSensors, useThrottle, useTimeouts, useWheelSwipe, withPlugins };
package/dist/index.js CHANGED
@@ -114,6 +114,11 @@ function stopNavigationEventsPropagation() {
114
114
  function calculatePreload(carousel, slides, minimum = 0) {
115
115
  return Math.min(carousel.preload, Math.max(carousel.finite ? slides.length - 1 : Math.floor(slides.length / 2), minimum));
116
116
  }
117
+ const isReact19 = Number(React.version.split(".")[0]) >= 19;
118
+ function makeInertWhen(condition) {
119
+ const legacyValue = condition ? "" : undefined;
120
+ return { inert: isReact19 ? condition : legacyValue };
121
+ }
117
122
 
118
123
  const LightboxDefaultProps = {
119
124
  open: false,
@@ -834,7 +839,8 @@ function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidt
834
839
  const intent = React.useRef(0);
835
840
  const intentCleanup = React.useRef();
836
841
  const resetCleanup = React.useRef();
837
- const wheelResidualMomentum = React.useRef(0);
842
+ const wheelInertia = React.useRef(0);
843
+ const wheelInertiaCleanup = React.useRef();
838
844
  const startTime = React.useRef(0);
839
845
  const { setTimeout, clearTimeout } = useTimeouts();
840
846
  const cancelSwipeIntentCleanup = React.useCallback(() => {
@@ -871,9 +877,20 @@ function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidt
871
877
  if (Math.abs(event.deltaY) > Math.abs(event.deltaX)) {
872
878
  return;
873
879
  }
880
+ const setWheelInertia = (inertia) => {
881
+ wheelInertia.current = inertia;
882
+ clearTimeout(wheelInertiaCleanup.current);
883
+ wheelInertiaCleanup.current =
884
+ inertia > 0
885
+ ? setTimeout(() => {
886
+ wheelInertia.current = 0;
887
+ wheelInertiaCleanup.current = undefined;
888
+ }, 300)
889
+ : undefined;
890
+ };
874
891
  if (swipeState === SwipeState.NONE) {
875
- if (Math.abs(event.deltaX) <= 1.2 * Math.abs(wheelResidualMomentum.current)) {
876
- wheelResidualMomentum.current = event.deltaX;
892
+ if (Math.abs(event.deltaX) <= 1.2 * Math.abs(wheelInertia.current)) {
893
+ setWheelInertia(event.deltaX);
877
894
  return;
878
895
  }
879
896
  if (!isSwipeValid(-event.deltaX)) {
@@ -883,7 +900,7 @@ function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidt
883
900
  cancelSwipeIntentCleanup();
884
901
  if (Math.abs(intent.current) > 30) {
885
902
  intent.current = 0;
886
- wheelResidualMomentum.current = 0;
903
+ setWheelInertia(0);
887
904
  startTime.current = Date.now();
888
905
  onSwipeStart();
889
906
  }
@@ -904,14 +921,14 @@ function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidt
904
921
  onSwipeProgress(newSwipeOffset);
905
922
  cancelSwipeResetCleanup();
906
923
  if (Math.abs(newSwipeOffset) > 0.2 * containerWidth) {
907
- wheelResidualMomentum.current = event.deltaX;
924
+ setWheelInertia(event.deltaX);
908
925
  onSwipeFinish(newSwipeOffset, Date.now() - startTime.current);
909
926
  return;
910
927
  }
911
928
  resetCleanup.current = setTimeout(() => handleCancelSwipe(newSwipeOffset), 2 * swipeAnimationDuration);
912
929
  }
913
930
  else {
914
- wheelResidualMomentum.current = event.deltaX;
931
+ setWheelInertia(event.deltaX);
915
932
  }
916
933
  });
917
934
  React.useEffect(() => subscribeSensors(EVENT_ON_WHEEL, onWheel), [subscribeSensors, onWheel]);
@@ -1203,13 +1220,21 @@ function cssSlidePrefix(value) {
1203
1220
  function CarouselSlide({ slide, offset }) {
1204
1221
  const containerRef = React.useRef(null);
1205
1222
  const { currentIndex } = useLightboxState();
1206
- const { slideRect, close } = useController();
1223
+ const { slideRect, close, focus } = useController();
1207
1224
  const { render, carousel: { imageFit, imageProps }, on: { click: onClick }, controller: { closeOnBackdropClick }, styles: { slide: style }, } = useLightboxProps();
1225
+ const { getOwnerDocument } = useDocumentContext();
1226
+ const offscreen = offset !== 0;
1227
+ React.useEffect(() => {
1228
+ var _a;
1229
+ if (offscreen && ((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.contains(getOwnerDocument().activeElement))) {
1230
+ focus();
1231
+ }
1232
+ }, [offscreen, focus, getOwnerDocument]);
1208
1233
  const renderSlide = () => {
1209
1234
  var _a, _b, _c, _d;
1210
1235
  let rendered = (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, { slide, offset, rect: slideRect });
1211
1236
  if (!rendered && isImageSlide(slide)) {
1212
- rendered = (React.createElement(ImageSlide, { slide: slide, offset: offset, render: render, rect: slideRect, imageFit: imageFit, imageProps: imageProps, onClick: offset === 0 ? () => onClick === null || onClick === void 0 ? void 0 : onClick({ index: currentIndex }) : undefined }));
1237
+ rendered = (React.createElement(ImageSlide, { slide: slide, offset: offset, render: render, rect: slideRect, imageFit: imageFit, imageProps: imageProps, onClick: !offscreen ? () => onClick === null || onClick === void 0 ? void 0 : onClick({ index: currentIndex }) : undefined }));
1213
1238
  }
1214
1239
  return rendered ? (React.createElement(React.Fragment, null, (_b = render.slideHeader) === null || _b === void 0 ? void 0 :
1215
1240
  _b.call(render, { slide }),
@@ -1228,7 +1253,7 @@ function CarouselSlide({ slide, offset }) {
1228
1253
  close();
1229
1254
  }
1230
1255
  };
1231
- return (React.createElement("div", { ref: containerRef, className: clsx(cssClass(cssSlidePrefix()), offset === 0 && cssClass(cssSlidePrefix("current")), cssClass(CLASS_FLEX_CENTER)), "aria-hidden": offset !== 0, onClick: handleBackdropClick, style: style }, renderSlide()));
1256
+ return (React.createElement("div", { ref: containerRef, className: clsx(cssClass(cssSlidePrefix()), !offscreen && cssClass(cssSlidePrefix("current")), cssClass(CLASS_FLEX_CENTER)), ...makeInertWhen(offscreen), onClick: handleBackdropClick, style: style }, renderSlide()));
1232
1257
  }
1233
1258
  function Placeholder() {
1234
1259
  const style = useLightboxProps().styles.slide;
@@ -1422,7 +1447,7 @@ function Portal({ children, animation, styles, className, on, portal, close }) {
1422
1447
  for (let i = 0; i < elements.length; i += 1) {
1423
1448
  const element = elements[i];
1424
1449
  if (["TEMPLATE", "SCRIPT", "STYLE"].indexOf(element.tagName) === -1 && element !== node) {
1425
- cleanup.current.push(setAttribute(element, "inert", "true"));
1450
+ cleanup.current.push(setAttribute(element, "inert", ""));
1426
1451
  cleanup.current.push(setAttribute(element, "aria-hidden", "true"));
1427
1452
  }
1428
1453
  }
@@ -1529,4 +1554,4 @@ function Lightbox({ carousel, animation, render, toolbar, controller, noScroll,
1529
1554
  React.createElement(EventsProvider, null, renderNode(createNode(RootModule, config), props))))));
1530
1555
  }
1531
1556
 
1532
- export { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, CLASS_FLEX_CENTER, CLASS_NO_SCROLL, CLASS_NO_SCROLL_PADDING, CLASS_SLIDE_WRAPPER, Carousel, CarouselModule, CloseIcon, Controller, ControllerContext, ControllerModule, DocumentContext, DocumentContextProvider, ELEMENT_BUTTON, ELEMENT_ICON, EVENT_ON_KEY_DOWN, EVENT_ON_KEY_UP, EVENT_ON_POINTER_CANCEL, EVENT_ON_POINTER_DOWN, EVENT_ON_POINTER_LEAVE, EVENT_ON_POINTER_MOVE, EVENT_ON_POINTER_UP, EVENT_ON_WHEEL, ErrorIcon, EventsContext, EventsProvider, IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER, IconButton, ImageSlide, Lightbox, LightboxDefaultProps, LightboxDispatchContext, LightboxPropsContext, LightboxPropsProvider, LightboxRoot, LightboxStateContext, LightboxStateProvider, LoadingIcon, MODULE_CAROUSEL, MODULE_CONTROLLER, MODULE_NAVIGATION, MODULE_NO_SCROLL, MODULE_PORTAL, MODULE_ROOT, MODULE_TOOLBAR, Navigation, NavigationButton, NavigationModule, NextIcon, NoScroll, NoScrollModule, Portal, PortalModule, PreviousIcon, Root, RootModule, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, SwipeState, TimeoutsContext, TimeoutsProvider, Toolbar, ToolbarModule, UNKNOWN_ACTION_TYPE, VK_ARROW_LEFT, VK_ARROW_RIGHT, VK_ESCAPE, activeSlideStatus, addToolbarButton, calculatePreload, cleanup, clsx, composePrefix, computeSlideRect, createIcon, createIconDisabled, createModule, createNode, cssClass, cssVar, Lightbox as default, devicePixelRatio, getSlide, getSlideIfPresent, getSlideIndex, getSlideKey, hasSlides, hasWindow, isImageFitCover, isImageSlide, label, makeComposePrefix, makeUseContext, parseInt, parseLengthPercentage, round, setRef, stopNavigationEventsPropagation, useAnimation, useContainerRect, useController, useDelay, useDocumentContext, useEventCallback, useEvents, useForkRef, useKeyboardNavigation, useLayoutEffect, useLightboxDispatch, useLightboxProps, useLightboxState, useLoseFocus, useMotionPreference, useNavigationState, usePointerEvents, usePointerSwipe, usePreventWheelDefaults, useRTL, useSensors, useThrottle, useTimeouts, useWheelSwipe, withPlugins };
1557
+ export { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, CLASS_FLEX_CENTER, CLASS_NO_SCROLL, CLASS_NO_SCROLL_PADDING, CLASS_SLIDE_WRAPPER, Carousel, CarouselModule, CloseIcon, Controller, ControllerContext, ControllerModule, DocumentContext, DocumentContextProvider, ELEMENT_BUTTON, ELEMENT_ICON, EVENT_ON_KEY_DOWN, EVENT_ON_KEY_UP, EVENT_ON_POINTER_CANCEL, EVENT_ON_POINTER_DOWN, EVENT_ON_POINTER_LEAVE, EVENT_ON_POINTER_MOVE, EVENT_ON_POINTER_UP, EVENT_ON_WHEEL, ErrorIcon, EventsContext, EventsProvider, IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER, IconButton, ImageSlide, Lightbox, LightboxDefaultProps, LightboxDispatchContext, LightboxPropsContext, LightboxPropsProvider, LightboxRoot, LightboxStateContext, LightboxStateProvider, LoadingIcon, MODULE_CAROUSEL, MODULE_CONTROLLER, MODULE_NAVIGATION, MODULE_NO_SCROLL, MODULE_PORTAL, MODULE_ROOT, MODULE_TOOLBAR, Navigation, NavigationButton, NavigationModule, NextIcon, NoScroll, NoScrollModule, Portal, PortalModule, PreviousIcon, Root, RootModule, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, SwipeState, TimeoutsContext, TimeoutsProvider, Toolbar, ToolbarModule, UNKNOWN_ACTION_TYPE, VK_ARROW_LEFT, VK_ARROW_RIGHT, VK_ESCAPE, activeSlideStatus, addToolbarButton, calculatePreload, cleanup, clsx, composePrefix, computeSlideRect, createIcon, createIconDisabled, createModule, createNode, cssClass, cssVar, Lightbox as default, devicePixelRatio, getSlide, getSlideIfPresent, getSlideIndex, getSlideKey, hasSlides, hasWindow, isImageFitCover, isImageSlide, label, makeComposePrefix, makeInertWhen, makeUseContext, parseInt, parseLengthPercentage, round, setRef, stopNavigationEventsPropagation, useAnimation, useContainerRect, useController, useDelay, useDocumentContext, useEventCallback, useEvents, useForkRef, useKeyboardNavigation, useLayoutEffect, useLightboxDispatch, useLightboxProps, useLightboxState, useLoseFocus, useMotionPreference, useNavigationState, usePointerEvents, usePointerSwipe, usePreventWheelDefaults, useRTL, useSensors, useThrottle, useTimeouts, useWheelSwipe, withPlugins };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yet-another-react-lightbox",
3
- "version": "3.21.4",
3
+ "version": "3.21.6",
4
4
  "description": "Modern React lightbox component",
5
5
  "author": "Igor Danchenko",
6
6
  "license": "MIT",