yet-another-react-lightbox 1.13.4 → 2.0.0-rc.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.
Files changed (121) hide show
  1. package/dist/Lightbox.js +1 -1
  2. package/dist/core/components/IconButton.d.ts +1 -1
  3. package/dist/core/components/IconButton.js +3 -2
  4. package/dist/core/components/ImageSlide.js +15 -24
  5. package/dist/core/consts.d.ts +36 -0
  6. package/dist/core/consts.js +36 -0
  7. package/dist/core/contexts/Events.d.ts +5 -9
  8. package/dist/core/contexts/Events.js +23 -25
  9. package/dist/core/contexts/LightboxState.d.ts +20 -0
  10. package/dist/core/contexts/LightboxState.js +23 -0
  11. package/dist/core/contexts/Timeouts.d.ts +1 -2
  12. package/dist/core/contexts/Timeouts.js +26 -29
  13. package/dist/core/contexts/index.d.ts +1 -0
  14. package/dist/core/contexts/index.js +1 -0
  15. package/dist/core/hooks/index.d.ts +2 -1
  16. package/dist/core/hooks/index.js +2 -1
  17. package/dist/core/hooks/useEventCallback.d.ts +1 -0
  18. package/dist/core/hooks/useEventCallback.js +9 -0
  19. package/dist/core/hooks/useForkRef.d.ts +3 -0
  20. package/dist/core/hooks/useForkRef.js +15 -0
  21. package/dist/core/hooks/useMotionPreference.js +1 -2
  22. package/dist/core/hooks/useSensors.d.ts +4 -5
  23. package/dist/core/hooks/useSensors.js +9 -12
  24. package/dist/core/modules/Carousel.js +29 -31
  25. package/dist/core/modules/Controller.d.ts +3 -7
  26. package/dist/core/modules/Controller.js +144 -263
  27. package/dist/core/modules/Core.js +6 -4
  28. package/dist/core/modules/Navigation.js +16 -13
  29. package/dist/core/modules/NoScroll.js +4 -3
  30. package/dist/core/modules/Portal.js +51 -40
  31. package/dist/core/modules/Toolbar.js +6 -4
  32. package/dist/core/modules/controller/index.d.ts +8 -0
  33. package/dist/core/modules/controller/index.js +9 -0
  34. package/dist/core/modules/controller/useOffset.d.ts +2 -0
  35. package/dist/core/modules/controller/useOffset.js +10 -0
  36. package/dist/core/modules/controller/usePointerSwipe.d.ts +3 -0
  37. package/dist/core/modules/controller/usePointerSwipe.js +61 -0
  38. package/dist/core/modules/controller/usePreventSwipeNavigation.d.ts +3 -0
  39. package/dist/core/modules/controller/usePreventSwipeNavigation.js +20 -0
  40. package/dist/core/modules/controller/useWheelSwipe.d.ts +3 -0
  41. package/dist/core/modules/controller/useWheelSwipe.js +94 -0
  42. package/dist/core/utils.d.ts +12 -1
  43. package/dist/core/utils.js +14 -0
  44. package/dist/plugins/captions/Captions.d.ts +7 -0
  45. package/dist/plugins/captions/Captions.js +23 -0
  46. package/dist/plugins/captions/CaptionsContext.d.ts +8 -0
  47. package/dist/plugins/captions/CaptionsContext.js +15 -0
  48. package/dist/plugins/captions/Description.d.ts +5 -0
  49. package/dist/plugins/captions/Description.js +17 -0
  50. package/dist/plugins/captions/Title.d.ts +5 -0
  51. package/dist/plugins/captions/Title.js +9 -0
  52. package/dist/plugins/{captions.css → captions/captions.css} +0 -2
  53. package/dist/plugins/{Captions.d.ts → captions/index.d.ts} +3 -9
  54. package/dist/plugins/captions/index.js +2 -0
  55. package/dist/plugins/captions/utils.d.ts +1 -0
  56. package/dist/plugins/captions/utils.js +2 -0
  57. package/dist/plugins/fullscreen/Fullscreen.d.ts +3 -0
  58. package/dist/plugins/fullscreen/Fullscreen.js +17 -0
  59. package/dist/plugins/fullscreen/FullscreenButton.d.ts +8 -0
  60. package/dist/plugins/{Fullscreen.js → fullscreen/FullscreenButton.js} +16 -30
  61. package/dist/plugins/fullscreen/FullscreenContext.d.ts +5 -0
  62. package/dist/plugins/fullscreen/FullscreenContext.js +9 -0
  63. package/dist/plugins/{Fullscreen.d.ts → fullscreen/index.d.ts} +2 -11
  64. package/dist/plugins/fullscreen/index.js +2 -0
  65. package/dist/plugins/index.d.ts +7 -7
  66. package/dist/plugins/index.js +7 -7
  67. package/dist/plugins/inline/Inline.d.ts +3 -0
  68. package/dist/plugins/{Inline.js → inline/Inline.js} +5 -7
  69. package/dist/plugins/inline/index.d.ts +9 -0
  70. package/dist/plugins/inline/index.js +2 -0
  71. package/dist/plugins/slideshow/Slideshow.d.ts +7 -0
  72. package/dist/plugins/slideshow/Slideshow.js +20 -0
  73. package/dist/plugins/slideshow/SlideshowButton.d.ts +2 -0
  74. package/dist/plugins/{Slideshow.js → slideshow/SlideshowButton.js} +17 -44
  75. package/dist/plugins/{Slideshow.d.ts → slideshow/index.d.ts} +2 -4
  76. package/dist/plugins/slideshow/index.js +2 -0
  77. package/dist/plugins/thumbnails/Thumbnail.d.ts +21 -0
  78. package/dist/plugins/thumbnails/Thumbnail.js +45 -0
  79. package/dist/plugins/thumbnails/Thumbnails.d.ts +13 -0
  80. package/dist/plugins/thumbnails/Thumbnails.js +28 -0
  81. package/dist/plugins/thumbnails/ThumbnailsContainer.d.ts +3 -0
  82. package/dist/plugins/thumbnails/ThumbnailsContainer.js +14 -0
  83. package/dist/plugins/thumbnails/ThumbnailsTrack.d.ts +12 -0
  84. package/dist/plugins/thumbnails/ThumbnailsTrack.js +148 -0
  85. package/dist/plugins/{Thumbnails.d.ts → thumbnails/index.d.ts} +4 -16
  86. package/dist/plugins/thumbnails/index.js +2 -0
  87. package/dist/plugins/{thumbnails.css → thumbnails/thumbnails.css} +27 -37
  88. package/dist/plugins/thumbnails/utils.d.ts +2 -0
  89. package/dist/plugins/thumbnails/utils.js +4 -0
  90. package/dist/plugins/video/Video.d.ts +7 -0
  91. package/dist/plugins/video/Video.js +24 -0
  92. package/dist/plugins/video/VideoSlide.d.ts +9 -0
  93. package/dist/plugins/{Video.js → video/VideoSlide.js} +14 -39
  94. package/dist/plugins/{Video.d.ts → video/index.d.ts} +5 -13
  95. package/dist/plugins/video/index.js +2 -0
  96. package/dist/plugins/zoom/Zoom.d.ts +14 -0
  97. package/dist/plugins/zoom/Zoom.js +36 -0
  98. package/dist/plugins/zoom/ZoomButton.d.ts +7 -0
  99. package/dist/plugins/zoom/ZoomButton.js +50 -0
  100. package/dist/plugins/zoom/ZoomButtonsGroup.d.ts +5 -0
  101. package/dist/plugins/zoom/ZoomButtonsGroup.js +23 -0
  102. package/dist/plugins/zoom/ZoomContainer.d.ts +9 -0
  103. package/dist/plugins/zoom/ZoomContainer.js +303 -0
  104. package/dist/plugins/zoom/ZoomContext.d.ts +12 -0
  105. package/dist/plugins/zoom/ZoomContext.js +18 -0
  106. package/dist/plugins/zoom/ZoomWrapper.d.ts +3 -0
  107. package/dist/plugins/zoom/ZoomWrapper.js +26 -0
  108. package/dist/plugins/{Zoom.d.ts → zoom/index.d.ts} +5 -5
  109. package/dist/plugins/zoom/index.js +4 -0
  110. package/dist/props.d.ts +2 -0
  111. package/dist/props.js +31 -0
  112. package/dist/styles.css +33 -27
  113. package/dist/types.d.ts +8 -22
  114. package/dist/types.js +1 -30
  115. package/package.json +17 -17
  116. package/dist/core/hooks/useLatest.d.ts +0 -3
  117. package/dist/core/hooks/useLatest.js +0 -6
  118. package/dist/plugins/Captions.js +0 -58
  119. package/dist/plugins/Inline.d.ts +0 -15
  120. package/dist/plugins/Thumbnails.js +0 -243
  121. package/dist/plugins/Zoom.js +0 -441
package/dist/Lightbox.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { LightboxDefaultProps } from "./types.js";
2
+ import { LightboxDefaultProps } from "./props.js";
3
3
  import { CarouselModule, ControllerModule, CoreModule, createNode, NavigationModule, NoScrollModule, PortalModule, ToolbarModule, withPlugins, } from "./core/index.js";
4
4
  const renderNode = (node, props) => {
5
5
  var _a;
@@ -4,4 +4,4 @@ export declare type IconButtonProps = Omit<React.DetailedHTMLProps<React.ButtonH
4
4
  icon: React.ElementType;
5
5
  renderIcon?: () => React.ReactNode;
6
6
  };
7
- export declare const IconButton: React.ForwardRefExoticComponent<Pick<IconButtonProps, "icon" | "className" | "value" | "children" | "onPointerDown" | "onPointerMove" | "onPointerUp" | "onPointerLeave" | "onPointerCancel" | "onTouchStart" | "onTouchMove" | "onTouchEnd" | "onTouchCancel" | "onKeyDown" | "onKeyUp" | "onWheel" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "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" | "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" | "onTouchCancelCapture" | "onTouchEndCapture" | "onTouchMoveCapture" | "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" | "form" | "label" | "disabled" | "autoFocus" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "renderIcon"> & React.RefAttributes<HTMLButtonElement>>;
7
+ export declare const IconButton: React.ForwardRefExoticComponent<Pick<IconButtonProps, "icon" | "className" | "placeholder" | "onPointerDown" | "onPointerMove" | "onPointerUp" | "onPointerLeave" | "onPointerCancel" | "onKeyDown" | "onKeyUp" | "onWheel" | "value" | "children" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "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" | "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" | "form" | "label" | "disabled" | "autoFocus" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "renderIcon"> & React.RefAttributes<HTMLButtonElement>>;
@@ -1,8 +1,9 @@
1
1
  import * as React from "react";
2
2
  import { clsx, cssClass } from "../utils.js";
3
3
  import { useController } from "../modules/Controller.js";
4
+ import { ELEMENT_BUTTON, ELEMENT_ICON } from "../consts.js";
4
5
  export const IconButton = React.forwardRef(({ label, className, icon: Icon, renderIcon, onClick, style, ...rest }, ref) => {
5
- const { latestProps: { current: { styles }, }, } = useController();
6
- return (React.createElement("button", { ref: ref, type: "button", "aria-label": label, className: clsx(cssClass("button"), className), onClick: onClick, style: { ...style, ...styles.button }, ...rest }, renderIcon ? renderIcon() : React.createElement(Icon, { className: cssClass("icon"), style: styles.icon })));
6
+ const { styles } = useController().getLightboxProps();
7
+ return (React.createElement("button", { ref: ref, type: "button", "aria-label": label, className: clsx(cssClass(ELEMENT_BUTTON), className), onClick: onClick, style: { ...style, ...styles.button }, ...rest }, renderIcon ? renderIcon() : React.createElement(Icon, { className: cssClass(ELEMENT_ICON), style: styles.icon })));
7
8
  });
8
9
  IconButton.displayName = "IconButton";
@@ -1,13 +1,14 @@
1
1
  import * as React from "react";
2
- import { clsx, cssClass, hasWindow } from "../utils.js";
3
- import { useLatest } from "../hooks/index.js";
2
+ import { clsx, cssClass, hasWindow, makeComposePrefix } from "../utils.js";
3
+ import { useEventCallback } from "../hooks/index.js";
4
4
  import { useEvents } from "../contexts/index.js";
5
5
  import { ErrorIcon, LoadingIcon } from "./Icons.js";
6
- import { activeSlideStatus, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, } from "../consts.js";
6
+ import { activeSlideStatus, ELEMENT_ICON, IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, } from "../consts.js";
7
+ const slidePrefix = makeComposePrefix("slide");
8
+ const slideImagePrefix = makeComposePrefix("slide_image");
7
9
  export const ImageSlide = ({ slide: image, offset, render, rect, imageFit, onClick }) => {
8
10
  var _a, _b, _c, _d, _e, _f, _g;
9
11
  const [status, setStatus] = React.useState(SLIDE_STATUS_LOADING);
10
- const latestStatus = useLatest(status);
11
12
  const { publish } = useEvents();
12
13
  const imageRef = React.useRef(null);
13
14
  React.useEffect(() => {
@@ -15,8 +16,8 @@ export const ImageSlide = ({ slide: image, offset, render, rect, imageFit, onCli
15
16
  publish(activeSlideStatus(status));
16
17
  }
17
18
  }, [offset, status, publish]);
18
- const handleLoading = React.useCallback((img) => {
19
- if (latestStatus.current === SLIDE_STATUS_COMPLETE) {
19
+ const handleLoading = useEventCallback((img) => {
20
+ if (status === SLIDE_STATUS_COMPLETE) {
20
21
  return;
21
22
  }
22
23
  ("decode" in img ? img.decode() : Promise.resolve())
@@ -27,7 +28,7 @@ export const ImageSlide = ({ slide: image, offset, render, rect, imageFit, onCli
27
28
  }
28
29
  setStatus(SLIDE_STATUS_COMPLETE);
29
30
  });
30
- }, [latestStatus]);
31
+ });
31
32
  const setImageRef = React.useCallback((img) => {
32
33
  imageRef.current = img;
33
34
  if (img === null || img === void 0 ? void 0 : img.complete) {
@@ -40,10 +41,10 @@ export const ImageSlide = ({ slide: image, offset, render, rect, imageFit, onCli
40
41
  const onError = React.useCallback(() => {
41
42
  setStatus(SLIDE_STATUS_ERROR);
42
43
  }, []);
43
- const cover = image.imageFit === "cover" || (image.imageFit !== "contain" && imageFit === "cover");
44
+ const cover = image.imageFit === IMAGE_FIT_COVER || (image.imageFit !== IMAGE_FIT_CONTAIN && imageFit === IMAGE_FIT_COVER);
44
45
  const nonInfinite = (value, fallback) => (Number.isFinite(value) ? value : fallback);
45
46
  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);
46
- const maxHeight = nonInfinite(Math.max(...((_e = (_d = image.srcSet) === null || _d === void 0 ? void 0 : _d.map((x) => x.height).filter((x) => Boolean(x))) !== null && _e !== void 0 ? _e : []).concat(image.height ? [image.height] : [])), (image.aspectRatio && maxWidth ? maxWidth / image.aspectRatio : (_f = imageRef.current) === null || _f === void 0 ? void 0 : _f.naturalHeight) || 0);
47
+ 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);
47
48
  const style = maxWidth && maxHeight
48
49
  ? {
49
50
  maxWidth: `min(${maxWidth}px, 100%)`,
@@ -54,23 +55,13 @@ export const ImageSlide = ({ slide: image, offset, render, rect, imageFit, onCli
54
55
  maxHeight: "100%",
55
56
  };
56
57
  const srcSet = (_g = image.srcSet) === null || _g === void 0 ? void 0 : _g.sort((a, b) => a.width - b.width).map((item) => `${item.src} ${item.width}w`).join(", ");
57
- const estimateActualWidth = () => {
58
- if (rect && !cover) {
59
- if (image.width && image.height) {
60
- return (rect.height / image.height) * image.width;
61
- }
62
- if (image.aspectRatio) {
63
- return rect.height * image.aspectRatio;
64
- }
65
- }
66
- return Number.MAX_VALUE;
67
- };
58
+ const estimateActualWidth = () => rect && !cover && image.width && image.height ? (rect.height / image.height) * image.width : Number.MAX_VALUE;
68
59
  const sizes = srcSet && rect && hasWindow() ? `${Math.round(Math.min(estimateActualWidth(), rect.width))}px` : undefined;
69
60
  return (React.createElement(React.Fragment, null,
70
- React.createElement("img", { ref: setImageRef, onLoad: onLoad, onError: onError, onClick: onClick, className: clsx(cssClass("slide_image"), cover && cssClass("slide_image_cover"), status !== SLIDE_STATUS_COMPLETE && cssClass("slide_image_loading")), draggable: false, alt: image.alt, style: style, sizes: sizes, srcSet: srcSet, src: image.src }),
71
- status !== SLIDE_STATUS_COMPLETE && (React.createElement("div", { className: cssClass("slide_placeholder") },
61
+ React.createElement("img", { ref: setImageRef, onLoad: onLoad, onError: onError, onClick: onClick, className: clsx(cssClass(slideImagePrefix()), cover && cssClass(slideImagePrefix("cover")), status !== SLIDE_STATUS_COMPLETE && cssClass(slideImagePrefix("loading"))), draggable: false, alt: image.alt, style: style, sizes: sizes, srcSet: srcSet, src: image.src }),
62
+ status !== SLIDE_STATUS_COMPLETE && (React.createElement("div", { className: cssClass(slidePrefix(SLIDE_STATUS_PLACEHOLDER)) },
72
63
  status === SLIDE_STATUS_LOADING &&
73
- ((render === null || render === void 0 ? void 0 : render.iconLoading) ? (render.iconLoading()) : (React.createElement(LoadingIcon, { className: clsx(cssClass("icon"), cssClass("slide_loading")) }))),
64
+ ((render === null || render === void 0 ? void 0 : render.iconLoading) ? (render.iconLoading()) : (React.createElement(LoadingIcon, { className: clsx(cssClass(ELEMENT_ICON), cssClass(slidePrefix(SLIDE_STATUS_LOADING))) }))),
74
65
  status === SLIDE_STATUS_ERROR &&
75
- ((render === null || render === void 0 ? void 0 : render.iconError) ? (render.iconError()) : (React.createElement(ErrorIcon, { className: clsx(cssClass("icon"), cssClass("slide_error")) })))))));
66
+ ((render === null || render === void 0 ? void 0 : render.iconError) ? (render.iconError()) : (React.createElement(ErrorIcon, { className: clsx(cssClass(ELEMENT_ICON), cssClass(slidePrefix(SLIDE_STATUS_ERROR))) })))))));
76
67
  };
@@ -1,7 +1,21 @@
1
+ export declare const MODULE_CAROUSEL = "carousel";
2
+ export declare const MODULE_CONTROLLER = "controller";
3
+ export declare const MODULE_CORE = "core";
4
+ export declare const MODULE_NAVIGATION = "navigation";
5
+ export declare const MODULE_NO_SCROLL = "no-scroll";
6
+ export declare const MODULE_PORTAL = "portal";
7
+ export declare const MODULE_TOOLBAR = "toolbar";
8
+ export declare const PLUGIN_CAPTIONS = "captions";
9
+ export declare const PLUGIN_FULLSCREEN = "fullscreen";
10
+ export declare const PLUGIN_INLINE = "inline";
11
+ export declare const PLUGIN_SLIDESHOW = "slideshow";
12
+ export declare const PLUGIN_THUMBNAILS = "thumbnails";
13
+ export declare const PLUGIN_ZOOM = "zoom";
1
14
  export declare const SLIDE_STATUS_LOADING = "loading";
2
15
  export declare const SLIDE_STATUS_PLAYING = "playing";
3
16
  export declare const SLIDE_STATUS_ERROR = "error";
4
17
  export declare const SLIDE_STATUS_COMPLETE = "complete";
18
+ export declare const SLIDE_STATUS_PLACEHOLDER = "placeholder";
5
19
  export declare type SlideStatus = typeof SLIDE_STATUS_LOADING | typeof SLIDE_STATUS_PLAYING | typeof SLIDE_STATUS_ERROR | typeof SLIDE_STATUS_COMPLETE;
6
20
  export declare const activeSlideStatus: (status: SlideStatus) => string;
7
21
  export declare const ACTIVE_SLIDE_LOADING: string;
@@ -9,3 +23,25 @@ export declare const ACTIVE_SLIDE_PLAYING: string;
9
23
  export declare const ACTIVE_SLIDE_ERROR: string;
10
24
  export declare const ACTIVE_SLIDE_COMPLETE: string;
11
25
  export declare const YARL_EVENT_BACKDROP_CLICK = "backdrop_click";
26
+ export declare const CLASS_FULLSIZE = "fullsize";
27
+ export declare const CLASS_FLEX_CENTER = "flex_center";
28
+ export declare const CLASS_NO_SCROLL = "no_scroll";
29
+ export declare const CLASS_NO_SCROLL_PADDING = "no_scroll_padding";
30
+ export declare const ACTION_PREV = "prev";
31
+ export declare const ACTION_NEXT = "next";
32
+ export declare const ACTION_CLOSE = "close";
33
+ export declare const EVENT_ON_POINTER_DOWN = "onPointerDown";
34
+ export declare const EVENT_ON_POINTER_MOVE = "onPointerMove";
35
+ export declare const EVENT_ON_POINTER_UP = "onPointerUp";
36
+ export declare const EVENT_ON_POINTER_LEAVE = "onPointerLeave";
37
+ export declare const EVENT_ON_POINTER_CANCEL = "onPointerCancel";
38
+ export declare const EVENT_ON_KEY_DOWN = "onKeyDown";
39
+ export declare const EVENT_ON_KEY_UP = "onKeyUp";
40
+ export declare const EVENT_ON_WHEEL = "onWheel";
41
+ export declare const VK_ESCAPE = "Escape";
42
+ export declare const VK_ARROW_LEFT = "ArrowLeft";
43
+ export declare const VK_ARROW_RIGHT = "ArrowRight";
44
+ export declare const ELEMENT_BUTTON = "button";
45
+ export declare const ELEMENT_ICON = "icon";
46
+ export declare const IMAGE_FIT_CONTAIN = "contain";
47
+ export declare const IMAGE_FIT_COVER = "cover";
@@ -1,10 +1,46 @@
1
+ export const MODULE_CAROUSEL = "carousel";
2
+ export const MODULE_CONTROLLER = "controller";
3
+ export const MODULE_CORE = "core";
4
+ export const MODULE_NAVIGATION = "navigation";
5
+ export const MODULE_NO_SCROLL = "no-scroll";
6
+ export const MODULE_PORTAL = "portal";
7
+ export const MODULE_TOOLBAR = "toolbar";
8
+ export const PLUGIN_CAPTIONS = "captions";
9
+ export const PLUGIN_FULLSCREEN = "fullscreen";
10
+ export const PLUGIN_INLINE = "inline";
11
+ export const PLUGIN_SLIDESHOW = "slideshow";
12
+ export const PLUGIN_THUMBNAILS = "thumbnails";
13
+ export const PLUGIN_ZOOM = "zoom";
1
14
  export const SLIDE_STATUS_LOADING = "loading";
2
15
  export const SLIDE_STATUS_PLAYING = "playing";
3
16
  export const SLIDE_STATUS_ERROR = "error";
4
17
  export const SLIDE_STATUS_COMPLETE = "complete";
18
+ export const SLIDE_STATUS_PLACEHOLDER = "placeholder";
5
19
  export const activeSlideStatus = (status) => `active-slide-${status}`;
6
20
  export const ACTIVE_SLIDE_LOADING = activeSlideStatus(SLIDE_STATUS_LOADING);
7
21
  export const ACTIVE_SLIDE_PLAYING = activeSlideStatus(SLIDE_STATUS_PLAYING);
8
22
  export const ACTIVE_SLIDE_ERROR = activeSlideStatus(SLIDE_STATUS_ERROR);
9
23
  export const ACTIVE_SLIDE_COMPLETE = activeSlideStatus(SLIDE_STATUS_COMPLETE);
10
24
  export const YARL_EVENT_BACKDROP_CLICK = "backdrop_click";
25
+ export const CLASS_FULLSIZE = "fullsize";
26
+ export const CLASS_FLEX_CENTER = "flex_center";
27
+ export const CLASS_NO_SCROLL = "no_scroll";
28
+ export const CLASS_NO_SCROLL_PADDING = "no_scroll_padding";
29
+ export const ACTION_PREV = "prev";
30
+ export const ACTION_NEXT = "next";
31
+ export const ACTION_CLOSE = "close";
32
+ export const EVENT_ON_POINTER_DOWN = "onPointerDown";
33
+ export const EVENT_ON_POINTER_MOVE = "onPointerMove";
34
+ export const EVENT_ON_POINTER_UP = "onPointerUp";
35
+ export const EVENT_ON_POINTER_LEAVE = "onPointerLeave";
36
+ export const EVENT_ON_POINTER_CANCEL = "onPointerCancel";
37
+ export const EVENT_ON_KEY_DOWN = "onKeyDown";
38
+ export const EVENT_ON_KEY_UP = "onKeyUp";
39
+ export const EVENT_ON_WHEEL = "onWheel";
40
+ export const VK_ESCAPE = "Escape";
41
+ export const VK_ARROW_LEFT = "ArrowLeft";
42
+ export const VK_ARROW_RIGHT = "ArrowRight";
43
+ export const ELEMENT_BUTTON = "button";
44
+ export const ELEMENT_ICON = "icon";
45
+ export const IMAGE_FIT_CONTAIN = "contain";
46
+ export const IMAGE_FIT_COVER = "cover";
@@ -1,16 +1,12 @@
1
1
  import * as React from "react";
2
- export declare type Topic = string;
3
- export declare type Callback = (topic: Topic, event?: unknown) => void;
4
- export declare type Events = {
5
- [key: string]: Callback[];
6
- };
7
- export declare type Subscribe = (topic: Topic, callback: Callback) => () => void;
8
- export declare type Unsubscribe = (topic: Topic, callback: Callback) => void;
9
- export declare type Publish = (topic: Topic, event?: unknown) => void;
2
+ export declare type Callback = (event?: unknown) => void;
3
+ export declare type Subscribe = (topic: string, callback: Callback) => () => void;
4
+ export declare type Unsubscribe = (topic: string, callback: Callback) => void;
5
+ export declare type Publish = (topic: string, event?: unknown) => void;
10
6
  export declare type EventsContextType = {
11
7
  subscribe: Subscribe;
12
8
  unsubscribe: Unsubscribe;
13
9
  publish: Publish;
14
10
  };
15
11
  export declare const useEvents: () => EventsContextType;
16
- export declare const EventsProvider: ({ children }: React.PropsWithChildren<{}>) => JSX.Element;
12
+ export declare const EventsProvider: React.FC<React.PropsWithChildren>;
@@ -3,30 +3,28 @@ import { makeUseContext } from "../utils.js";
3
3
  const EventsContext = React.createContext(null);
4
4
  export const useEvents = makeUseContext("useEvents", "EventsContext", EventsContext);
5
5
  export const EventsProvider = ({ children }) => {
6
- const subscriptions = React.useRef({});
7
- const unsubscribe = (topic, callback) => {
8
- if (subscriptions.current[topic]) {
9
- subscriptions.current[topic] = subscriptions.current[topic].filter((cb) => cb !== callback);
10
- }
11
- };
12
- const subscribe = (topic, callback) => {
13
- if (!subscriptions.current[topic]) {
14
- subscriptions.current[topic] = [];
15
- }
16
- subscriptions.current[topic].push(callback);
17
- return () => unsubscribe(topic, callback);
18
- };
19
- const publish = (topic, event) => {
20
- var _a;
21
- (_a = subscriptions.current[topic]) === null || _a === void 0 ? void 0 : _a.forEach((callback) => callback(topic, event));
22
- };
6
+ const [subscriptions] = React.useState({});
23
7
  React.useEffect(() => () => {
24
- subscriptions.current = {};
25
- }, []);
26
- const context = React.useRef({
27
- subscribe,
28
- unsubscribe,
29
- publish,
30
- });
31
- return React.createElement(EventsContext.Provider, { value: context.current }, children);
8
+ Object.keys(subscriptions).forEach((key) => delete subscriptions[key]);
9
+ }, [subscriptions]);
10
+ const context = React.useMemo(() => {
11
+ const unsubscribe = (topic, callback) => {
12
+ if (subscriptions[topic]) {
13
+ subscriptions[topic] = subscriptions[topic].filter((cb) => cb !== callback);
14
+ }
15
+ };
16
+ const subscribe = (topic, callback) => {
17
+ if (!subscriptions[topic]) {
18
+ subscriptions[topic] = [];
19
+ }
20
+ subscriptions[topic].push(callback);
21
+ return () => unsubscribe(topic, callback);
22
+ };
23
+ const publish = (topic, event) => {
24
+ var _a;
25
+ (_a = subscriptions[topic]) === null || _a === void 0 ? void 0 : _a.forEach((callback) => callback(event));
26
+ };
27
+ return { publish, subscribe, unsubscribe };
28
+ }, [subscriptions]);
29
+ return React.createElement(EventsContext.Provider, { value: context }, children);
32
30
  };
@@ -0,0 +1,20 @@
1
+ import * as React from "react";
2
+ export declare type LightboxState = {
3
+ currentIndex: number;
4
+ globalIndex: number;
5
+ animationDuration: number;
6
+ };
7
+ declare type LightboxStateAction = {
8
+ increment?: number;
9
+ animationDuration: number;
10
+ };
11
+ export declare const useLightboxState: () => {
12
+ state: LightboxState;
13
+ dispatch: React.Dispatch<LightboxStateAction>;
14
+ };
15
+ declare type LightboxStateProviderProps = React.PropsWithChildren<{
16
+ slidesCount: number;
17
+ initialIndex: number;
18
+ }>;
19
+ export declare const LightboxStateProvider: React.FC<LightboxStateProviderProps>;
20
+ export {};
@@ -0,0 +1,23 @@
1
+ import * as React from "react";
2
+ import { makeUseContext } from "../utils.js";
3
+ const LightboxStateContext = React.createContext(null);
4
+ export const useLightboxState = makeUseContext("useLightboxState", "LightboxStateContext", LightboxStateContext);
5
+ const reducer = (slidesCount) => (state, action) => {
6
+ var _a;
7
+ return action.increment !== undefined || action.animationDuration !== undefined
8
+ ? {
9
+ currentIndex: (((state.currentIndex + (action.increment || 0)) % slidesCount) + slidesCount) % slidesCount,
10
+ globalIndex: state.globalIndex + (action.increment || 0),
11
+ animationDuration: (_a = action.animationDuration) !== null && _a !== void 0 ? _a : state.animationDuration,
12
+ }
13
+ : state;
14
+ };
15
+ export const LightboxStateProvider = ({ initialIndex, slidesCount, children, }) => {
16
+ const [state, dispatch] = React.useReducer(reducer(slidesCount), {
17
+ currentIndex: initialIndex,
18
+ globalIndex: initialIndex,
19
+ animationDuration: 0,
20
+ });
21
+ const context = React.useMemo(() => ({ state, dispatch }), [state, dispatch]);
22
+ return React.createElement(LightboxStateContext.Provider, { value: context }, children);
23
+ };
@@ -1,8 +1,7 @@
1
1
  import * as React from "react";
2
2
  export declare type TimeoutsContextType = {
3
- setTimeout: (func: () => void, time?: number) => number;
3
+ setTimeout: (fn: () => void, delay?: number) => number;
4
4
  clearTimeout: (id?: number) => void;
5
- clearTimeouts: () => void;
6
5
  };
7
6
  export declare const useTimeouts: () => TimeoutsContextType;
8
7
  export declare const TimeoutsProvider: ({ children }: React.PropsWithChildren<{}>) => JSX.Element;
@@ -3,33 +3,30 @@ import { isDefined, makeUseContext } from "../utils.js";
3
3
  const TimeoutsContext = React.createContext(null);
4
4
  export const useTimeouts = makeUseContext("useTimeouts", "TimeoutsContext", TimeoutsContext);
5
5
  export const TimeoutsProvider = ({ children }) => {
6
- const timeouts = React.useRef([]);
7
- const removeTimeout = (id) => {
8
- timeouts.current.splice(0, timeouts.current.length, ...timeouts.current.filter((tid) => tid !== id));
9
- };
10
- const setTimeout = (func, time) => {
11
- const id = window.setTimeout(() => {
12
- removeTimeout(id);
13
- func();
14
- }, time);
15
- timeouts.current.push(id);
16
- return id;
17
- };
18
- const clearTimeout = (id) => {
19
- if (isDefined(id)) {
20
- removeTimeout(id);
21
- window.clearTimeout(id);
22
- }
23
- };
24
- const clearTimeouts = () => {
25
- timeouts.current.forEach((tid) => window.clearTimeout(tid));
26
- timeouts.current.splice(0, timeouts.current.length);
27
- };
28
- React.useEffect(() => () => clearTimeouts(), []);
29
- const context = React.useRef({
30
- setTimeout,
31
- clearTimeout,
32
- clearTimeouts,
33
- });
34
- return React.createElement(TimeoutsContext.Provider, { value: context.current }, children);
6
+ const [timeouts] = React.useState([]);
7
+ React.useEffect(() => () => {
8
+ timeouts.forEach((tid) => window.clearTimeout(tid));
9
+ timeouts.splice(0, timeouts.length);
10
+ }, [timeouts]);
11
+ const context = React.useMemo(() => {
12
+ const removeTimeout = (id) => {
13
+ timeouts.splice(0, timeouts.length, ...timeouts.filter((tid) => tid !== id));
14
+ };
15
+ const setTimeout = (fn, delay) => {
16
+ const id = window.setTimeout(() => {
17
+ removeTimeout(id);
18
+ fn();
19
+ }, delay);
20
+ timeouts.push(id);
21
+ return id;
22
+ };
23
+ const clearTimeout = (id) => {
24
+ if (isDefined(id)) {
25
+ removeTimeout(id);
26
+ window.clearTimeout(id);
27
+ }
28
+ };
29
+ return { setTimeout, clearTimeout };
30
+ }, [timeouts]);
31
+ return React.createElement(TimeoutsContext.Provider, { value: context }, children);
35
32
  };
@@ -1,2 +1,3 @@
1
1
  export * from "./Events.js";
2
+ export * from "./LightboxState.js";
2
3
  export * from "./Timeouts.js";
@@ -1,2 +1,3 @@
1
1
  export * from "./Events.js";
2
+ export * from "./LightboxState.js";
2
3
  export * from "./Timeouts.js";
@@ -1,6 +1,7 @@
1
1
  export * from "./useContainerRect.js";
2
+ export * from "./useEventCallback.js";
3
+ export * from "./useForkRef.js";
2
4
  export * from "./useLayoutEffect.js";
3
- export * from "./useLatest.js";
4
5
  export * from "./useMotionPreference.js";
5
6
  export * from "./useRTL.js";
6
7
  export * from "./useSensors.js";
@@ -1,6 +1,7 @@
1
1
  export * from "./useContainerRect.js";
2
+ export * from "./useEventCallback.js";
3
+ export * from "./useForkRef.js";
2
4
  export * from "./useLayoutEffect.js";
3
- export * from "./useLatest.js";
4
5
  export * from "./useMotionPreference.js";
5
6
  export * from "./useRTL.js";
6
7
  export * from "./useSensors.js";
@@ -0,0 +1 @@
1
+ export declare const useEventCallback: <Args extends unknown[], Return>(fn: (...args: Args) => Return) => (...args: Args) => Return;
@@ -0,0 +1,9 @@
1
+ import * as React from "react";
2
+ import { useLayoutEffect } from "./useLayoutEffect.js";
3
+ export const useEventCallback = (fn) => {
4
+ const ref = React.useRef(fn);
5
+ useLayoutEffect(() => {
6
+ ref.current = fn;
7
+ });
8
+ return React.useCallback((...args) => { var _a; return (_a = ref.current) === null || _a === void 0 ? void 0 : _a.call(ref, ...args); }, []);
9
+ };
@@ -0,0 +1,3 @@
1
+ import * as React from "react";
2
+ export declare const setRef: <T>(ref: React.MutableRefObject<T | null> | ((instance: T | null) => void) | null | undefined, value: T | null) => void;
3
+ export declare const useForkRef: <InstanceA, InstanceB>(refA: React.Ref<InstanceA> | undefined, refB: React.Ref<InstanceB> | undefined) => React.Ref<InstanceA & InstanceB>;
@@ -0,0 +1,15 @@
1
+ import * as React from "react";
2
+ export const setRef = (ref, value) => {
3
+ if (typeof ref === "function") {
4
+ ref(value);
5
+ }
6
+ else if (ref) {
7
+ ref.current = value;
8
+ }
9
+ };
10
+ export const useForkRef = (refA, refB) => React.useMemo(() => refA == null && refB == null
11
+ ? null
12
+ : (refValue) => {
13
+ setRef(refA, refValue);
14
+ setRef(refB, refValue);
15
+ }, [refA, refB]);
@@ -1,8 +1,7 @@
1
1
  import * as React from "react";
2
- import { useLayoutEffect } from "./useLayoutEffect.js";
3
2
  export const useMotionPreference = () => {
4
3
  const [reduceMotion, setReduceMotion] = React.useState(false);
5
- useLayoutEffect(() => {
4
+ React.useEffect(() => {
6
5
  var _a;
7
6
  const mediaQuery = (_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, "(prefers-reduced-motion: reduce)");
8
7
  setReduceMotion(mediaQuery === null || mediaQuery === void 0 ? void 0 : mediaQuery.matches);
@@ -1,13 +1,12 @@
1
1
  import * as React from "react";
2
2
  export declare type PointerEventType = "onPointerDown" | "onPointerMove" | "onPointerUp" | "onPointerLeave" | "onPointerCancel";
3
- export declare type TouchEventType = "onTouchStart" | "onTouchMove" | "onTouchEnd" | "onTouchCancel";
4
3
  export declare type KeyboardEventType = "onKeyDown" | "onKeyUp";
5
4
  export declare type WheelEventType = "onWheel";
6
- export declare type SupportedEventType = PointerEventType | TouchEventType | KeyboardEventType | WheelEventType;
7
- export declare type ReactEventType<T, K> = K extends TouchEventType ? React.TouchEvent<T> : K extends KeyboardEventType ? React.KeyboardEvent<T> : K extends WheelEventType ? React.WheelEvent<T> : K extends PointerEventType ? React.PointerEvent<T> : never;
8
- export declare type EventCallback<T, P extends React.PointerEvent<T> | React.TouchEvent<T> | React.KeyboardEvent<T> | React.WheelEvent<T>> = (event: P) => void;
5
+ export declare type SupportedEventType = PointerEventType | KeyboardEventType | WheelEventType;
6
+ export declare type ReactEventType<T, K> = K extends KeyboardEventType ? React.KeyboardEvent<T> : K extends WheelEventType ? React.WheelEvent<T> : K extends PointerEventType ? React.PointerEvent<T> : never;
7
+ export declare type EventCallback<T, P extends React.PointerEvent<T> | React.KeyboardEvent<T> | React.WheelEvent<T>> = (event: P) => void;
9
8
  export declare type SubscribeSensors<T> = <ET extends SupportedEventType>(type: ET, callback: EventCallback<T, ReactEventType<T, ET>>) => () => void;
10
- export declare type RegisterSensors<T> = Required<Pick<React.HTMLAttributes<T>, PointerEventType>> & Required<Pick<React.HTMLAttributes<T>, TouchEventType>> & Required<Pick<React.HTMLAttributes<T>, KeyboardEventType>> & Required<Pick<React.HTMLAttributes<T>, WheelEventType>>;
9
+ export declare type RegisterSensors<T> = Required<Pick<React.HTMLAttributes<T>, PointerEventType>> & Required<Pick<React.HTMLAttributes<T>, KeyboardEventType>> & Required<Pick<React.HTMLAttributes<T>, WheelEventType>>;
11
10
  export declare type UseSensors<T> = {
12
11
  registerSensors: RegisterSensors<T>;
13
12
  subscribeSensors: SubscribeSensors<T>;
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
+ import { 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, } from "../consts.js";
2
3
  export const useSensors = () => {
3
4
  const [subscribers] = React.useState({});
4
5
  return React.useMemo(() => {
@@ -11,18 +12,14 @@ export const useSensors = () => {
11
12
  };
12
13
  return {
13
14
  registerSensors: {
14
- onPointerDown: (event) => notifySubscribers("onPointerDown", event),
15
- onPointerMove: (event) => notifySubscribers("onPointerMove", event),
16
- onPointerUp: (event) => notifySubscribers("onPointerUp", event),
17
- onPointerLeave: (event) => notifySubscribers("onPointerLeave", event),
18
- onPointerCancel: (event) => notifySubscribers("onPointerCancel", event),
19
- onTouchStart: (event) => notifySubscribers("onTouchStart", event),
20
- onTouchMove: (event) => notifySubscribers("onTouchMove", event),
21
- onTouchEnd: (event) => notifySubscribers("onTouchEnd", event),
22
- onTouchCancel: (event) => notifySubscribers("onTouchCancel", event),
23
- onKeyDown: (event) => notifySubscribers("onKeyDown", event),
24
- onKeyUp: (event) => notifySubscribers("onKeyUp", event),
25
- onWheel: (event) => notifySubscribers("onWheel", event),
15
+ onPointerDown: (event) => notifySubscribers(EVENT_ON_POINTER_DOWN, event),
16
+ onPointerMove: (event) => notifySubscribers(EVENT_ON_POINTER_MOVE, event),
17
+ onPointerUp: (event) => notifySubscribers(EVENT_ON_POINTER_UP, event),
18
+ onPointerLeave: (event) => notifySubscribers(EVENT_ON_POINTER_LEAVE, event),
19
+ onPointerCancel: (event) => notifySubscribers(EVENT_ON_POINTER_CANCEL, event),
20
+ onKeyDown: (event) => notifySubscribers(EVENT_ON_KEY_DOWN, event),
21
+ onKeyUp: (event) => notifySubscribers(EVENT_ON_KEY_UP, event),
22
+ onWheel: (event) => notifySubscribers(EVENT_ON_WHEEL, event),
26
23
  },
27
24
  subscribeSensors: (type, callback) => {
28
25
  if (!subscribers[type]) {