yet-another-react-lightbox 3.21.5 → 3.21.7

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.js CHANGED
@@ -839,7 +839,8 @@ function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidt
839
839
  const intent = React.useRef(0);
840
840
  const intentCleanup = React.useRef();
841
841
  const resetCleanup = React.useRef();
842
- const wheelResidualMomentum = React.useRef(0);
842
+ const wheelInertia = React.useRef(0);
843
+ const wheelInertiaCleanup = React.useRef();
843
844
  const startTime = React.useRef(0);
844
845
  const { setTimeout, clearTimeout } = useTimeouts();
845
846
  const cancelSwipeIntentCleanup = React.useCallback(() => {
@@ -876,9 +877,20 @@ function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidt
876
877
  if (Math.abs(event.deltaY) > Math.abs(event.deltaX)) {
877
878
  return;
878
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
+ };
879
891
  if (swipeState === SwipeState.NONE) {
880
- if (Math.abs(event.deltaX) <= 1.2 * Math.abs(wheelResidualMomentum.current)) {
881
- wheelResidualMomentum.current = event.deltaX;
892
+ if (Math.abs(event.deltaX) <= 1.2 * Math.abs(wheelInertia.current)) {
893
+ setWheelInertia(event.deltaX);
882
894
  return;
883
895
  }
884
896
  if (!isSwipeValid(-event.deltaX)) {
@@ -888,7 +900,7 @@ function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidt
888
900
  cancelSwipeIntentCleanup();
889
901
  if (Math.abs(intent.current) > 30) {
890
902
  intent.current = 0;
891
- wheelResidualMomentum.current = 0;
903
+ setWheelInertia(0);
892
904
  startTime.current = Date.now();
893
905
  onSwipeStart();
894
906
  }
@@ -909,14 +921,14 @@ function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidt
909
921
  onSwipeProgress(newSwipeOffset);
910
922
  cancelSwipeResetCleanup();
911
923
  if (Math.abs(newSwipeOffset) > 0.2 * containerWidth) {
912
- wheelResidualMomentum.current = event.deltaX;
924
+ setWheelInertia(event.deltaX);
913
925
  onSwipeFinish(newSwipeOffset, Date.now() - startTime.current);
914
926
  return;
915
927
  }
916
928
  resetCleanup.current = setTimeout(() => handleCancelSwipe(newSwipeOffset), 2 * swipeAnimationDuration);
917
929
  }
918
930
  else {
919
- wheelResidualMomentum.current = event.deltaX;
931
+ setWheelInertia(event.deltaX);
920
932
  }
921
933
  });
922
934
  React.useEffect(() => subscribeSensors(EVENT_ON_WHEEL, onWheel), [subscribeSensors, onWheel]);
@@ -79,6 +79,11 @@ function VideoSlide({ slide, offset }) {
79
79
  height: "100%",
80
80
  ...(width ? { maxWidth: `${width}px` } : null),
81
81
  }, className: clsx(cssClass("video_container"), cssClass(CLASS_FLEX_CENTER), cssClass(CLASS_SLIDE_WRAPPER)) }, containerRect && (React.createElement("video", { ref: setVideoRef, poster: poster, ...scaleWidthAndHeight(), ...resolveBoolean("controls"), ...resolveBoolean("playsInline"), ...resolveBoolean("loop"), ...resolveBoolean("muted"), ...resolveBoolean("playsInline"), ...resolveBoolean("disablePictureInPicture"), ...resolveBoolean("disableRemotePlayback"), ...resolveString("controlsList"), ...resolveString("crossOrigin"), ...resolveString("preload"), onPlay: () => {
82
+ var _a;
83
+ if (offset !== 0) {
84
+ (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.pause();
85
+ return;
86
+ }
82
87
  publish(ACTIVE_SLIDE_PLAYING);
83
88
  }, onEnded: () => {
84
89
  publish(ACTIVE_SLIDE_COMPLETE);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yet-another-react-lightbox",
3
- "version": "3.21.5",
3
+ "version": "3.21.7",
4
4
  "description": "Modern React lightbox component",
5
5
  "author": "Igor Danchenko",
6
6
  "license": "MIT",