yet-another-react-lightbox 3.5.4 → 3.7.0

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 (204) hide show
  1. package/README.md +3 -3
  2. package/dist/index.d.ts +240 -4
  3. package/dist/index.js +1368 -4
  4. package/dist/plugins/captions/captions.css +1 -33
  5. package/dist/plugins/captions/captions.css.d.ts +2 -0
  6. package/dist/plugins/captions/index.d.ts +8 -4
  7. package/dist/plugins/captions/index.js +104 -3
  8. package/dist/plugins/counter/counter.css +1 -16
  9. package/dist/plugins/counter/counter.css.d.ts +2 -0
  10. package/dist/plugins/counter/index.d.ts +8 -3
  11. package/dist/plugins/counter/index.js +18 -2
  12. package/dist/plugins/download/index.d.ts +6 -3
  13. package/dist/plugins/download/index.js +90 -3
  14. package/dist/plugins/fullscreen/index.d.ts +8 -4
  15. package/dist/plugins/fullscreen/index.js +128 -3
  16. package/dist/plugins/index.d.ts +9 -9
  17. package/dist/plugins/index.js +9 -9
  18. package/dist/plugins/inline/index.d.ts +8 -3
  19. package/dist/plugins/inline/index.js +26 -2
  20. package/dist/plugins/slideshow/index.d.ts +8 -4
  21. package/dist/plugins/slideshow/index.js +113 -3
  22. package/dist/plugins/thumbnails/index.d.ts +7 -4
  23. package/dist/plugins/thumbnails/index.js +261 -3
  24. package/dist/plugins/thumbnails/thumbnails.css +1 -139
  25. package/dist/plugins/thumbnails/thumbnails.css.d.ts +2 -0
  26. package/dist/plugins/video/index.d.ts +7 -2
  27. package/dist/plugins/video/index.js +109 -2
  28. package/dist/plugins/zoom/index.d.ts +7 -4
  29. package/dist/plugins/zoom/index.js +500 -3
  30. package/dist/styles.css +1 -281
  31. package/dist/styles.css.d.ts +2 -0
  32. package/dist/types.d.ts +125 -47
  33. package/dist/types.js +51 -1
  34. package/package.json +34 -10
  35. package/dist/Lightbox.d.ts +0 -4
  36. package/dist/Lightbox.js +0 -46
  37. package/dist/core/components/IconButton.d.ts +0 -7
  38. package/dist/core/components/IconButton.js +0 -8
  39. package/dist/core/components/Icons.d.ts +0 -29
  40. package/dist/core/components/Icons.js +0 -27
  41. package/dist/core/components/ImageSlide.d.ts +0 -13
  42. package/dist/core/components/ImageSlide.js +0 -68
  43. package/dist/core/components/index.d.ts +0 -3
  44. package/dist/core/components/index.js +0 -3
  45. package/dist/core/config.d.ts +0 -7
  46. package/dist/core/config.js +0 -93
  47. package/dist/core/consts.d.ts +0 -50
  48. package/dist/core/consts.js +0 -49
  49. package/dist/core/contexts/Events.d.ts +0 -17
  50. package/dist/core/contexts/Events.js +0 -29
  51. package/dist/core/contexts/LightboxProps.d.ts +0 -6
  52. package/dist/core/contexts/LightboxProps.js +0 -7
  53. package/dist/core/contexts/LightboxState.d.ts +0 -27
  54. package/dist/core/contexts/LightboxState.js +0 -49
  55. package/dist/core/contexts/Timeouts.d.ts +0 -8
  56. package/dist/core/contexts/Timeouts.js +0 -32
  57. package/dist/core/contexts/index.d.ts +0 -4
  58. package/dist/core/contexts/index.js +0 -4
  59. package/dist/core/hooks/index.d.ts +0 -11
  60. package/dist/core/hooks/index.js +0 -11
  61. package/dist/core/hooks/useAnimation.d.ts +0 -15
  62. package/dist/core/hooks/useAnimation.js +0 -57
  63. package/dist/core/hooks/useContainerRect.d.ts +0 -7
  64. package/dist/core/hooks/useContainerRect.js +0 -36
  65. package/dist/core/hooks/useDelay.d.ts +0 -1
  66. package/dist/core/hooks/useDelay.js +0 -10
  67. package/dist/core/hooks/useEventCallback.d.ts +0 -1
  68. package/dist/core/hooks/useEventCallback.js +0 -9
  69. package/dist/core/hooks/useForkRef.d.ts +0 -3
  70. package/dist/core/hooks/useForkRef.js +0 -17
  71. package/dist/core/hooks/useLayoutEffect.d.ts +0 -2
  72. package/dist/core/hooks/useLayoutEffect.js +0 -3
  73. package/dist/core/hooks/useLoseFocus.d.ts +0 -4
  74. package/dist/core/hooks/useLoseFocus.js +0 -19
  75. package/dist/core/hooks/useMotionPreference.d.ts +0 -1
  76. package/dist/core/hooks/useMotionPreference.js +0 -13
  77. package/dist/core/hooks/useRTL.d.ts +0 -1
  78. package/dist/core/hooks/useRTL.js +0 -9
  79. package/dist/core/hooks/useSensors.d.ts +0 -14
  80. package/dist/core/hooks/useSensors.js +0 -38
  81. package/dist/core/hooks/useThrottle.d.ts +0 -1
  82. package/dist/core/hooks/useThrottle.js +0 -16
  83. package/dist/core/index.d.ts +0 -7
  84. package/dist/core/index.js +0 -7
  85. package/dist/core/modules/Carousel.d.ts +0 -4
  86. package/dist/core/modules/Carousel.js +0 -72
  87. package/dist/core/modules/Controller.d.ts +0 -31
  88. package/dist/core/modules/Controller.js +0 -215
  89. package/dist/core/modules/Navigation.d.ts +0 -13
  90. package/dist/core/modules/Navigation.js +0 -35
  91. package/dist/core/modules/NoScroll.d.ts +0 -4
  92. package/dist/core/modules/NoScroll.js +0 -52
  93. package/dist/core/modules/Portal.d.ts +0 -4
  94. package/dist/core/modules/Portal.js +0 -92
  95. package/dist/core/modules/Root.d.ts +0 -4
  96. package/dist/core/modules/Root.js +0 -7
  97. package/dist/core/modules/Toolbar.d.ts +0 -4
  98. package/dist/core/modules/Toolbar.js +0 -25
  99. package/dist/core/modules/controller/index.d.ts +0 -8
  100. package/dist/core/modules/controller/index.js +0 -9
  101. package/dist/core/modules/controller/usePointerSwipe.d.ts +0 -2
  102. package/dist/core/modules/controller/usePointerSwipe.js +0 -72
  103. package/dist/core/modules/controller/usePreventSwipeNavigation.d.ts +0 -3
  104. package/dist/core/modules/controller/usePreventSwipeNavigation.js +0 -20
  105. package/dist/core/modules/controller/useWheelSwipe.d.ts +0 -3
  106. package/dist/core/modules/controller/useWheelSwipe.js +0 -92
  107. package/dist/core/modules/index.d.ts +0 -7
  108. package/dist/core/modules/index.js +0 -7
  109. package/dist/core/utils.d.ts +0 -36
  110. package/dist/core/utils.js +0 -70
  111. package/dist/plugins/captions/Captions.d.ts +0 -3
  112. package/dist/plugins/captions/Captions.js +0 -25
  113. package/dist/plugins/captions/CaptionsButton.d.ts +0 -2
  114. package/dist/plugins/captions/CaptionsButton.js +0 -16
  115. package/dist/plugins/captions/CaptionsContext.d.ts +0 -5
  116. package/dist/plugins/captions/CaptionsContext.js +0 -16
  117. package/dist/plugins/captions/Description.d.ts +0 -4
  118. package/dist/plugins/captions/Description.js +0 -27
  119. package/dist/plugins/captions/Title.d.ts +0 -4
  120. package/dist/plugins/captions/Title.js +0 -16
  121. package/dist/plugins/captions/props.d.ts +0 -19
  122. package/dist/plugins/captions/props.js +0 -14
  123. package/dist/plugins/captions/utils.d.ts +0 -1
  124. package/dist/plugins/captions/utils.js +0 -2
  125. package/dist/plugins/counter/Counter.d.ts +0 -5
  126. package/dist/plugins/counter/Counter.js +0 -14
  127. package/dist/plugins/download/Download.d.ts +0 -2
  128. package/dist/plugins/download/Download.js +0 -9
  129. package/dist/plugins/download/DownloadButton.d.ts +0 -2
  130. package/dist/plugins/download/DownloadButton.js +0 -19
  131. package/dist/plugins/download/FileSaver.d.ts +0 -1
  132. package/dist/plugins/download/FileSaver.js +0 -60
  133. package/dist/plugins/fullscreen/Fullscreen.d.ts +0 -3
  134. package/dist/plugins/fullscreen/Fullscreen.js +0 -13
  135. package/dist/plugins/fullscreen/FullscreenButton.d.ts +0 -3
  136. package/dist/plugins/fullscreen/FullscreenButton.js +0 -16
  137. package/dist/plugins/fullscreen/FullscreenContext.d.ts +0 -5
  138. package/dist/plugins/fullscreen/FullscreenContext.js +0 -93
  139. package/dist/plugins/fullscreen/props.d.ts +0 -10
  140. package/dist/plugins/fullscreen/props.js +0 -8
  141. package/dist/plugins/inline/Inline.d.ts +0 -3
  142. package/dist/plugins/inline/Inline.js +0 -18
  143. package/dist/plugins/inline/InlineContainer.d.ts +0 -4
  144. package/dist/plugins/inline/InlineContainer.js +0 -5
  145. package/dist/plugins/slideshow/Slideshow.d.ts +0 -3
  146. package/dist/plugins/slideshow/Slideshow.js +0 -13
  147. package/dist/plugins/slideshow/SlideshowButton.d.ts +0 -2
  148. package/dist/plugins/slideshow/SlideshowButton.js +0 -14
  149. package/dist/plugins/slideshow/SlideshowContext.d.ts +0 -5
  150. package/dist/plugins/slideshow/SlideshowContext.js +0 -79
  151. package/dist/plugins/slideshow/props.d.ts +0 -12
  152. package/dist/plugins/slideshow/props.js +0 -9
  153. package/dist/plugins/thumbnails/Thumbnail.d.ts +0 -15
  154. package/dist/plugins/thumbnails/Thumbnail.js +0 -51
  155. package/dist/plugins/thumbnails/Thumbnails.d.ts +0 -3
  156. package/dist/plugins/thumbnails/Thumbnails.js +0 -22
  157. package/dist/plugins/thumbnails/ThumbnailsButton.d.ts +0 -2
  158. package/dist/plugins/thumbnails/ThumbnailsButton.js +0 -16
  159. package/dist/plugins/thumbnails/ThumbnailsContext.d.ts +0 -6
  160. package/dist/plugins/thumbnails/ThumbnailsContext.js +0 -24
  161. package/dist/plugins/thumbnails/ThumbnailsTrack.d.ts +0 -5
  162. package/dist/plugins/thumbnails/ThumbnailsTrack.js +0 -141
  163. package/dist/plugins/thumbnails/props.d.ts +0 -40
  164. package/dist/plugins/thumbnails/props.js +0 -21
  165. package/dist/plugins/thumbnails/utils.d.ts +0 -2
  166. package/dist/plugins/thumbnails/utils.js +0 -4
  167. package/dist/plugins/video/Video.d.ts +0 -3
  168. package/dist/plugins/video/Video.js +0 -21
  169. package/dist/plugins/video/VideoSlide.d.ts +0 -8
  170. package/dist/plugins/video/VideoSlide.js +0 -74
  171. package/dist/plugins/video/props.d.ts +0 -29
  172. package/dist/plugins/video/props.js +0 -13
  173. package/dist/plugins/zoom/ResponsiveImage.d.ts +0 -11
  174. package/dist/plugins/zoom/ResponsiveImage.js +0 -58
  175. package/dist/plugins/zoom/Zoom.d.ts +0 -3
  176. package/dist/plugins/zoom/Zoom.js +0 -18
  177. package/dist/plugins/zoom/ZoomButton.d.ts +0 -8
  178. package/dist/plugins/zoom/ZoomButton.js +0 -27
  179. package/dist/plugins/zoom/ZoomButtonsGroup.d.ts +0 -2
  180. package/dist/plugins/zoom/ZoomButtonsGroup.js +0 -22
  181. package/dist/plugins/zoom/ZoomController.d.ts +0 -12
  182. package/dist/plugins/zoom/ZoomController.js +0 -17
  183. package/dist/plugins/zoom/ZoomToolbarControl.d.ts +0 -2
  184. package/dist/plugins/zoom/ZoomToolbarControl.js +0 -12
  185. package/dist/plugins/zoom/ZoomWrapper.d.ts +0 -5
  186. package/dist/plugins/zoom/ZoomWrapper.js +0 -36
  187. package/dist/plugins/zoom/hooks/index.d.ts +0 -6
  188. package/dist/plugins/zoom/hooks/index.js +0 -6
  189. package/dist/plugins/zoom/hooks/useZoomAnimation.d.ts +0 -2
  190. package/dist/plugins/zoom/hooks/useZoomAnimation.js +0 -39
  191. package/dist/plugins/zoom/hooks/useZoomCallback.d.ts +0 -1
  192. package/dist/plugins/zoom/hooks/useZoomCallback.js +0 -12
  193. package/dist/plugins/zoom/hooks/useZoomImageRect.d.ts +0 -5
  194. package/dist/plugins/zoom/hooks/useZoomImageRect.js +0 -41
  195. package/dist/plugins/zoom/hooks/useZoomProps.d.ts +0 -13
  196. package/dist/plugins/zoom/hooks/useZoomProps.js +0 -6
  197. package/dist/plugins/zoom/hooks/useZoomSensors.d.ts +0 -3
  198. package/dist/plugins/zoom/hooks/useZoomSensors.js +0 -154
  199. package/dist/plugins/zoom/hooks/useZoomState.d.ts +0 -12
  200. package/dist/plugins/zoom/hooks/useZoomState.js +0 -63
  201. package/dist/plugins/zoom/props.d.ts +0 -25
  202. package/dist/plugins/zoom/props.js +0 -15
  203. package/dist/props.d.ts +0 -2
  204. package/dist/props.js +0 -38
package/dist/index.js CHANGED
@@ -1,4 +1,1368 @@
1
- import { Lightbox } from "./Lightbox.js";
2
- export * from "./types.js";
3
- export * from "./Lightbox.js";
4
- export default Lightbox;
1
+ 'use client';
2
+ import * as React from 'react';
3
+ import { ACTION_CLOSE, IMAGE_FIT_CONTAIN, MODULE_CONTROLLER, IMAGE_FIT_COVER, UNKNOWN_ACTION_TYPE, ELEMENT_BUTTON, ELEMENT_ICON, EVENT_ON_POINTER_DOWN, EVENT_ON_POINTER_MOVE, EVENT_ON_POINTER_UP, EVENT_ON_POINTER_LEAVE, EVENT_ON_POINTER_CANCEL, EVENT_ON_KEY_DOWN, EVENT_ON_KEY_UP, EVENT_ON_WHEEL, SLIDE_STATUS_LOADING, activeSlideStatus, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_PLACEHOLDER, ACTION_PREV, ACTION_NEXT, ACTION_SWIPE, VK_ESCAPE, CLASS_FLEX_CENTER, MODULE_CAROUSEL, CLASS_FULLSIZE, VK_ARROW_LEFT, VK_ARROW_RIGHT, MODULE_NAVIGATION, CLASS_NO_SCROLL, CLASS_NO_SCROLL_PADDING, MODULE_NO_SCROLL, MODULE_PORTAL, MODULE_ROOT, MODULE_TOOLBAR } from './types.js';
4
+ import { createPortal } from 'react-dom';
5
+ export { ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, PLUGIN_CAPTIONS, PLUGIN_COUNTER, PLUGIN_DOWNLOAD, PLUGIN_FULLSCREEN, PLUGIN_INLINE, PLUGIN_SLIDESHOW, PLUGIN_THUMBNAILS, PLUGIN_ZOOM, SLIDE_STATUS_PLAYING } from './types.js';
6
+
7
+ const LightboxDefaultProps = {
8
+ open: false,
9
+ close: () => { },
10
+ index: 0,
11
+ slides: [],
12
+ render: {},
13
+ plugins: [],
14
+ toolbar: { buttons: [ACTION_CLOSE] },
15
+ labels: {},
16
+ animation: {
17
+ fade: 250,
18
+ swipe: 500,
19
+ easing: {
20
+ fade: "ease",
21
+ swipe: "ease-out",
22
+ navigation: "ease-in-out",
23
+ },
24
+ },
25
+ carousel: {
26
+ finite: false,
27
+ preload: 2,
28
+ padding: "16px",
29
+ spacing: "30%",
30
+ imageFit: IMAGE_FIT_CONTAIN,
31
+ },
32
+ controller: {
33
+ ref: null,
34
+ focus: true,
35
+ aria: false,
36
+ touchAction: "none",
37
+ closeOnPullDown: false,
38
+ closeOnBackdropClick: false,
39
+ },
40
+ portal: {},
41
+ on: {},
42
+ styles: {},
43
+ className: "",
44
+ };
45
+
46
+ function createModule(name, component) {
47
+ return { name, component };
48
+ }
49
+ function createNode(module, children) {
50
+ return { module, children };
51
+ }
52
+ function traverseNode(node, target, apply) {
53
+ if (node.module.name === target) {
54
+ return apply(node);
55
+ }
56
+ if (node.children) {
57
+ return [
58
+ createNode(node.module, node.children.flatMap((n) => { var _a; return (_a = traverseNode(n, target, apply)) !== null && _a !== void 0 ? _a : []; })),
59
+ ];
60
+ }
61
+ return [node];
62
+ }
63
+ function traverse(nodes, target, apply) {
64
+ return nodes.flatMap((node) => { var _a; return (_a = traverseNode(node, target, apply)) !== null && _a !== void 0 ? _a : []; });
65
+ }
66
+ function withPlugins(root, plugins = [], augmentations = []) {
67
+ let config = root;
68
+ const contains = (target) => {
69
+ const nodes = [...config];
70
+ while (nodes.length > 0) {
71
+ const node = nodes.pop();
72
+ if ((node === null || node === void 0 ? void 0 : node.module.name) === target)
73
+ return true;
74
+ if (node === null || node === void 0 ? void 0 : node.children)
75
+ nodes.push(...node.children);
76
+ }
77
+ return false;
78
+ };
79
+ const addParent = (target, module) => {
80
+ if (target === "") {
81
+ config = [createNode(module, config)];
82
+ return;
83
+ }
84
+ config = traverse(config, target, (node) => [createNode(module, [node])]);
85
+ };
86
+ const append = (target, module) => {
87
+ config = traverse(config, target, (node) => [createNode(node.module, [createNode(module, node.children)])]);
88
+ };
89
+ const addChild = (target, module, precede) => {
90
+ config = traverse(config, target, (node) => {
91
+ var _a;
92
+ return [
93
+ createNode(node.module, [
94
+ ...(precede ? [createNode(module)] : []),
95
+ ...((_a = node.children) !== null && _a !== void 0 ? _a : []),
96
+ ...(!precede ? [createNode(module)] : []),
97
+ ]),
98
+ ];
99
+ });
100
+ };
101
+ const addSibling = (target, module, precede) => {
102
+ config = traverse(config, target, (node) => [
103
+ ...(precede ? [createNode(module)] : []),
104
+ node,
105
+ ...(!precede ? [createNode(module)] : []),
106
+ ]);
107
+ };
108
+ const addModule = (module) => {
109
+ append(MODULE_CONTROLLER, module);
110
+ };
111
+ const replace = (target, module) => {
112
+ config = traverse(config, target, (node) => [createNode(module, node.children)]);
113
+ };
114
+ const remove = (target) => {
115
+ config = traverse(config, target, (node) => node.children);
116
+ };
117
+ const augment = (augmentation) => {
118
+ augmentations.push(augmentation);
119
+ };
120
+ plugins.forEach((plugin) => {
121
+ plugin({
122
+ contains,
123
+ addParent,
124
+ append,
125
+ addChild,
126
+ addSibling,
127
+ addModule,
128
+ replace,
129
+ remove,
130
+ augment,
131
+ });
132
+ });
133
+ return {
134
+ config,
135
+ augmentation: (props) => augmentations.reduce((acc, augmentation) => augmentation(acc), props),
136
+ };
137
+ }
138
+
139
+ const clsx = (...classes) => [...classes].filter((cls) => Boolean(cls)).join(" ");
140
+ const cssPrefix$3 = "yarl__";
141
+ const cssClass = (name) => `${cssPrefix$3}${name}`;
142
+ const cssVar = (name) => `--${cssPrefix$3}${name}`;
143
+ const composePrefix = (base, prefix) => `${base}${prefix ? `_${prefix}` : ""}`;
144
+ const makeComposePrefix = (base) => (prefix) => composePrefix(base, prefix);
145
+ const label = (labels, lbl) => (labels && labels[lbl] ? labels[lbl] : lbl);
146
+ const cleanup = (...cleaners) => () => {
147
+ cleaners.forEach((cleaner) => {
148
+ cleaner();
149
+ });
150
+ };
151
+ const makeUseContext = (name, contextName, context) => () => {
152
+ const ctx = React.useContext(context);
153
+ if (!ctx) {
154
+ throw new Error(`${name} must be used within a ${contextName}.Provider`);
155
+ }
156
+ return ctx;
157
+ };
158
+ const hasWindow = () => typeof window !== "undefined";
159
+ function round(value, decimals = 0) {
160
+ const factor = 10 ** decimals;
161
+ return Math.round((value + Number.EPSILON) * factor) / factor;
162
+ }
163
+ const isImageSlide = (slide) => slide.type === undefined || slide.type === "image";
164
+ const isImageFitCover = (image, imageFit) => image.imageFit === IMAGE_FIT_COVER || (image.imageFit !== IMAGE_FIT_CONTAIN && imageFit === IMAGE_FIT_COVER);
165
+ function parseLengthPercentage(input) {
166
+ if (typeof input === "number") {
167
+ return { pixel: input };
168
+ }
169
+ if (typeof input === "string") {
170
+ const value = parseInt(input, 10);
171
+ return input.endsWith("%") ? { percent: value } : { pixel: value };
172
+ }
173
+ return { pixel: 0 };
174
+ }
175
+ function computeSlideRect(containerRect, padding) {
176
+ const paddingValue = parseLengthPercentage(padding);
177
+ const paddingPixels = paddingValue.percent !== undefined ? (containerRect.width / 100) * paddingValue.percent : paddingValue.pixel;
178
+ return {
179
+ width: Math.max(containerRect.width - 2 * paddingPixels, 0),
180
+ height: Math.max(containerRect.height - 2 * paddingPixels, 0),
181
+ };
182
+ }
183
+ const devicePixelRatio = () => (hasWindow() ? window === null || window === void 0 ? void 0 : window.devicePixelRatio : undefined) || 1;
184
+ const getSlideIndex = (index, slidesCount) => slidesCount > 0 ? ((index % slidesCount) + slidesCount) % slidesCount : 0;
185
+ const hasSlides = (slides) => slides.length > 0;
186
+ const getSlide = (slides, index) => slides[getSlideIndex(index, slides.length)];
187
+ const getSlideIfPresent = (slides, index) => hasSlides(slides) ? getSlide(slides, index) : undefined;
188
+ function addToolbarButton(toolbar, key, button) {
189
+ if (!button)
190
+ return toolbar;
191
+ const { buttons, ...restToolbar } = toolbar;
192
+ const index = buttons.findIndex((item) => item === key);
193
+ const buttonWithKey = React.isValidElement(button) ? React.cloneElement(button, { key }, null) : button;
194
+ if (index >= 0) {
195
+ const result = [...buttons];
196
+ result.splice(index, 1, buttonWithKey);
197
+ return { buttons: result, ...restToolbar };
198
+ }
199
+ return { buttons: [buttonWithKey, ...buttons], ...restToolbar };
200
+ }
201
+ function stopNavigationEventsPropagation() {
202
+ const stopPropagation = (event) => {
203
+ event.stopPropagation();
204
+ };
205
+ return { onPointerDown: stopPropagation, onKeyDown: stopPropagation, onWheel: stopPropagation };
206
+ }
207
+
208
+ const EventsContext = React.createContext(null);
209
+ const useEvents = makeUseContext("useEvents", "EventsContext", EventsContext);
210
+ function EventsProvider({ children }) {
211
+ const [subscriptions] = React.useState({});
212
+ React.useEffect(() => () => {
213
+ Object.keys(subscriptions).forEach((topic) => delete subscriptions[topic]);
214
+ }, [subscriptions]);
215
+ const context = React.useMemo(() => {
216
+ const unsubscribe = (topic, callback) => {
217
+ var _a;
218
+ (_a = subscriptions[topic]) === null || _a === void 0 ? void 0 : _a.splice(0, subscriptions[topic].length, ...subscriptions[topic].filter((cb) => cb !== callback));
219
+ };
220
+ const subscribe = (topic, callback) => {
221
+ if (!subscriptions[topic]) {
222
+ subscriptions[topic] = [];
223
+ }
224
+ subscriptions[topic].push(callback);
225
+ return () => unsubscribe(topic, callback);
226
+ };
227
+ const publish = (...[topic, event]) => {
228
+ var _a;
229
+ (_a = subscriptions[topic]) === null || _a === void 0 ? void 0 : _a.forEach((callback) => callback(event));
230
+ };
231
+ return { publish, subscribe, unsubscribe };
232
+ }, [subscriptions]);
233
+ return React.createElement(EventsContext.Provider, { value: context }, children);
234
+ }
235
+
236
+ const LightboxPropsContext = React.createContext(null);
237
+ const useLightboxProps = makeUseContext("useLightboxProps", "LightboxPropsContext", LightboxPropsContext);
238
+ function LightboxPropsProvider({ children, ...props }) {
239
+ return React.createElement(LightboxPropsContext.Provider, { value: props }, children);
240
+ }
241
+
242
+ const LightboxStateContext = React.createContext(null);
243
+ const useLightboxState = makeUseContext("useLightboxState", "LightboxStateContext", LightboxStateContext);
244
+ const LightboxDispatchContext = React.createContext(null);
245
+ const useLightboxDispatch = makeUseContext("useLightboxDispatch", "LightboxDispatchContext", LightboxDispatchContext);
246
+ function reducer(state, action) {
247
+ switch (action.type) {
248
+ case "swipe": {
249
+ const { slides } = state;
250
+ const increment = (action === null || action === void 0 ? void 0 : action.increment) || 0;
251
+ const globalIndex = state.globalIndex + increment;
252
+ const currentIndex = getSlideIndex(globalIndex, slides.length);
253
+ const currentSlide = getSlideIfPresent(slides, currentIndex);
254
+ const animation = increment || action.duration
255
+ ? {
256
+ increment,
257
+ duration: action.duration,
258
+ easing: action.easing,
259
+ }
260
+ : undefined;
261
+ return { slides, currentIndex, globalIndex, currentSlide, animation };
262
+ }
263
+ case "update":
264
+ return {
265
+ slides: action.slides,
266
+ currentIndex: action.index,
267
+ globalIndex: action.index,
268
+ currentSlide: getSlideIfPresent(action.slides, action.index),
269
+ };
270
+ default:
271
+ throw new Error(UNKNOWN_ACTION_TYPE);
272
+ }
273
+ }
274
+ function LightboxStateProvider({ slides, index, children }) {
275
+ const [state, dispatch] = React.useReducer(reducer, {
276
+ slides,
277
+ currentIndex: index,
278
+ globalIndex: index,
279
+ currentSlide: getSlideIfPresent(slides, index),
280
+ });
281
+ React.useEffect(() => {
282
+ dispatch({ type: "update", slides, index });
283
+ }, [slides, index]);
284
+ const context = React.useMemo(() => ({ ...state, state, dispatch }), [state, dispatch]);
285
+ return (React.createElement(LightboxDispatchContext.Provider, { value: dispatch },
286
+ React.createElement(LightboxStateContext.Provider, { value: context }, children)));
287
+ }
288
+
289
+ const TimeoutsContext = React.createContext(null);
290
+ const useTimeouts = makeUseContext("useTimeouts", "TimeoutsContext", TimeoutsContext);
291
+ function TimeoutsProvider({ children }) {
292
+ const [timeouts] = React.useState([]);
293
+ React.useEffect(() => () => {
294
+ timeouts.forEach((tid) => window.clearTimeout(tid));
295
+ timeouts.splice(0, timeouts.length);
296
+ }, [timeouts]);
297
+ const context = React.useMemo(() => {
298
+ const removeTimeout = (id) => {
299
+ timeouts.splice(0, timeouts.length, ...timeouts.filter((tid) => tid !== id));
300
+ };
301
+ const setTimeout = (fn, delay) => {
302
+ const id = window.setTimeout(() => {
303
+ removeTimeout(id);
304
+ fn();
305
+ }, delay);
306
+ timeouts.push(id);
307
+ return id;
308
+ };
309
+ const clearTimeout = (id) => {
310
+ if (id !== undefined) {
311
+ removeTimeout(id);
312
+ window.clearTimeout(id);
313
+ }
314
+ };
315
+ return { setTimeout, clearTimeout };
316
+ }, [timeouts]);
317
+ return React.createElement(TimeoutsContext.Provider, { value: context }, children);
318
+ }
319
+
320
+ const IconButton = React.forwardRef(function IconButton({ label: label$1, className, icon: Icon, renderIcon, onClick, style, ...rest }, ref) {
321
+ const { styles, labels } = useLightboxProps();
322
+ return (React.createElement("button", { ref: ref, type: "button", "aria-label": label(labels, label$1), 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 })));
323
+ });
324
+
325
+ function svgIcon(name, children) {
326
+ const icon = (props) => (React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "24", height: "24", "aria-hidden": "true", focusable: "false", ...props }, children));
327
+ icon.displayName = name;
328
+ return icon;
329
+ }
330
+ function createIcon(name, glyph) {
331
+ return svgIcon(name, React.createElement("g", { fill: "currentColor" },
332
+ React.createElement("path", { d: "M0 0h24v24H0z", fill: "none" }),
333
+ glyph));
334
+ }
335
+ function createIconDisabled(name, glyph) {
336
+ return svgIcon(name, React.createElement(React.Fragment, null,
337
+ React.createElement("defs", null,
338
+ React.createElement("mask", { id: "strike" },
339
+ React.createElement("path", { d: "M0 0h24v24H0z", fill: "white" }),
340
+ React.createElement("path", { d: "M0 0L24 24", stroke: "black", strokeWidth: 4 }))),
341
+ React.createElement("path", { d: "M0.70707 2.121320L21.878680 23.292883", stroke: "currentColor", strokeWidth: 2 }),
342
+ React.createElement("g", { fill: "currentColor", mask: "url(#strike)" },
343
+ React.createElement("path", { d: "M0 0h24v24H0z", fill: "none" }),
344
+ glyph)));
345
+ }
346
+ const CloseIcon = createIcon("Close", React.createElement("path", { d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" }));
347
+ const PreviousIcon = createIcon("Previous", React.createElement("path", { d: "M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z" }));
348
+ const NextIcon = createIcon("Next", React.createElement("path", { d: "M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z" }));
349
+ const LoadingIcon = createIcon("Loading", React.createElement(React.Fragment, null, Array.from({ length: 8 }).map((_, index, array) => (React.createElement("line", { key: index, x1: "12", y1: "6.5", x2: "12", y2: "1.8", strokeLinecap: "round", strokeWidth: "2.6", stroke: "currentColor", strokeOpacity: (1 / array.length) * (index + 1), transform: `rotate(${(360 / array.length) * index}, 12, 12)` })))));
350
+ const ErrorIcon = createIcon("Error", React.createElement("path", { d: "M21.9,21.9l-8.49-8.49l0,0L3.59,3.59l0,0L2.1,2.1L0.69,3.51L3,5.83V19c0,1.1,0.9,2,2,2h13.17l2.31,2.31L21.9,21.9z M5,18 l3.5-4.5l2.5,3.01L12.17,15l3,3H5z M21,18.17L5.83,3H19c1.1,0,2,0.9,2,2V18.17z" }));
351
+
352
+ const useLayoutEffect = hasWindow() ? React.useLayoutEffect : React.useEffect;
353
+
354
+ function useMotionPreference() {
355
+ const [reduceMotion, setReduceMotion] = React.useState(false);
356
+ React.useEffect(() => {
357
+ var _a, _b;
358
+ const mediaQuery = (_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, "(prefers-reduced-motion: reduce)");
359
+ setReduceMotion(mediaQuery === null || mediaQuery === void 0 ? void 0 : mediaQuery.matches);
360
+ const listener = (event) => setReduceMotion(event.matches);
361
+ (_b = mediaQuery === null || mediaQuery === void 0 ? void 0 : mediaQuery.addEventListener) === null || _b === void 0 ? void 0 : _b.call(mediaQuery, "change", listener);
362
+ return () => { var _a; return (_a = mediaQuery === null || mediaQuery === void 0 ? void 0 : mediaQuery.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(mediaQuery, "change", listener); };
363
+ }, []);
364
+ return reduceMotion;
365
+ }
366
+
367
+ function currentTransformation(node) {
368
+ let x = 0;
369
+ let y = 0;
370
+ let z = 0;
371
+ const matrix = window.getComputedStyle(node).transform;
372
+ const matcher = matrix.match(/matrix.*\((.+)\)/);
373
+ if (matcher) {
374
+ const values = matcher[1].split(",").map((str) => Number.parseInt(str, 10));
375
+ if (values.length === 6) {
376
+ x = values[4];
377
+ y = values[5];
378
+ }
379
+ else if (values.length === 16) {
380
+ x = values[12];
381
+ y = values[13];
382
+ z = values[14];
383
+ }
384
+ }
385
+ return { x, y, z };
386
+ }
387
+ function useAnimation(nodeRef, computeAnimation) {
388
+ const snapshot = React.useRef();
389
+ const animation = React.useRef();
390
+ const reduceMotion = useMotionPreference();
391
+ useLayoutEffect(() => {
392
+ var _a, _b, _c;
393
+ if (nodeRef.current && snapshot.current !== undefined && !reduceMotion) {
394
+ const { keyframes, duration, easing, onfinish } = computeAnimation(snapshot.current, nodeRef.current.getBoundingClientRect(), currentTransformation(nodeRef.current)) || {};
395
+ if (keyframes && duration) {
396
+ (_a = animation.current) === null || _a === void 0 ? void 0 : _a.cancel();
397
+ animation.current = undefined;
398
+ try {
399
+ animation.current = (_c = (_b = nodeRef.current).animate) === null || _c === void 0 ? void 0 : _c.call(_b, keyframes, { duration, easing });
400
+ }
401
+ catch (err) {
402
+ console.error(err);
403
+ }
404
+ if (animation.current) {
405
+ animation.current.onfinish = () => {
406
+ animation.current = undefined;
407
+ onfinish === null || onfinish === void 0 ? void 0 : onfinish();
408
+ };
409
+ }
410
+ }
411
+ }
412
+ snapshot.current = undefined;
413
+ });
414
+ return {
415
+ prepareAnimation: (currentSnapshot) => {
416
+ snapshot.current = currentSnapshot;
417
+ },
418
+ isAnimationPlaying: () => { var _a; return ((_a = animation.current) === null || _a === void 0 ? void 0 : _a.playState) === "running"; },
419
+ };
420
+ }
421
+
422
+ function useContainerRect() {
423
+ const [containerRect, setContainerRect] = React.useState();
424
+ const containerRef = React.useRef(null);
425
+ const observerRef = React.useRef();
426
+ const setContainerRef = React.useCallback((node) => {
427
+ containerRef.current = node;
428
+ if (observerRef.current) {
429
+ observerRef.current.disconnect();
430
+ observerRef.current = undefined;
431
+ }
432
+ const updateContainerRect = () => {
433
+ if (node) {
434
+ const styles = window.getComputedStyle(node);
435
+ const parse = (value) => parseFloat(value) || 0;
436
+ setContainerRect({
437
+ width: Math.round(node.clientWidth - parse(styles.paddingLeft) - parse(styles.paddingRight)),
438
+ height: Math.round(node.clientHeight - parse(styles.paddingTop) - parse(styles.paddingBottom)),
439
+ });
440
+ }
441
+ else {
442
+ setContainerRect(undefined);
443
+ }
444
+ };
445
+ updateContainerRect();
446
+ if (node && typeof ResizeObserver !== "undefined") {
447
+ observerRef.current = new ResizeObserver(updateContainerRect);
448
+ observerRef.current.observe(node);
449
+ }
450
+ }, []);
451
+ return React.useMemo(() => ({
452
+ setContainerRef,
453
+ containerRef,
454
+ containerRect,
455
+ }), [setContainerRef, containerRef, containerRect]);
456
+ }
457
+
458
+ function useDelay() {
459
+ const timeoutId = React.useRef();
460
+ const { setTimeout, clearTimeout } = useTimeouts();
461
+ return React.useCallback((callback, delay) => {
462
+ clearTimeout(timeoutId.current);
463
+ timeoutId.current = setTimeout(callback, delay > 0 ? delay : 0);
464
+ }, [setTimeout, clearTimeout]);
465
+ }
466
+
467
+ function useEventCallback(fn) {
468
+ const ref = React.useRef(fn);
469
+ useLayoutEffect(() => {
470
+ ref.current = fn;
471
+ });
472
+ return React.useCallback((...args) => { var _a; return (_a = ref.current) === null || _a === void 0 ? void 0 : _a.call(ref, ...args); }, []);
473
+ }
474
+
475
+ function setRef(ref, value) {
476
+ if (typeof ref === "function") {
477
+ ref(value);
478
+ }
479
+ else if (ref) {
480
+ ref.current = value;
481
+ }
482
+ }
483
+ function useForkRef(refA, refB) {
484
+ return React.useMemo(() => refA == null && refB == null
485
+ ? null
486
+ : (refValue) => {
487
+ setRef(refA, refValue);
488
+ setRef(refB, refValue);
489
+ }, [refA, refB]);
490
+ }
491
+
492
+ function useLoseFocus(focus, disabled = false) {
493
+ const focused = React.useRef(disabled);
494
+ useLayoutEffect(() => {
495
+ if (disabled) {
496
+ focus();
497
+ }
498
+ }, [disabled, focus]);
499
+ const onFocus = React.useCallback(() => {
500
+ focused.current = true;
501
+ }, []);
502
+ const onBlur = React.useCallback(() => {
503
+ focused.current = false;
504
+ }, []);
505
+ return { onFocus, onBlur };
506
+ }
507
+
508
+ function useRTL() {
509
+ const [isRTL, setIsRTL] = React.useState(false);
510
+ useLayoutEffect(() => {
511
+ setIsRTL(window.getComputedStyle(window.document.documentElement).direction === "rtl");
512
+ }, []);
513
+ return isRTL;
514
+ }
515
+
516
+ function useSensors() {
517
+ const [subscribers] = React.useState({});
518
+ return React.useMemo(() => {
519
+ const notifySubscribers = (type, event) => {
520
+ var _a;
521
+ (_a = subscribers[type]) === null || _a === void 0 ? void 0 : _a.forEach((listener) => {
522
+ if (!event.isPropagationStopped())
523
+ listener(event);
524
+ });
525
+ };
526
+ return {
527
+ registerSensors: {
528
+ onPointerDown: (event) => notifySubscribers(EVENT_ON_POINTER_DOWN, event),
529
+ onPointerMove: (event) => notifySubscribers(EVENT_ON_POINTER_MOVE, event),
530
+ onPointerUp: (event) => notifySubscribers(EVENT_ON_POINTER_UP, event),
531
+ onPointerLeave: (event) => notifySubscribers(EVENT_ON_POINTER_LEAVE, event),
532
+ onPointerCancel: (event) => notifySubscribers(EVENT_ON_POINTER_CANCEL, event),
533
+ onKeyDown: (event) => notifySubscribers(EVENT_ON_KEY_DOWN, event),
534
+ onKeyUp: (event) => notifySubscribers(EVENT_ON_KEY_UP, event),
535
+ onWheel: (event) => notifySubscribers(EVENT_ON_WHEEL, event),
536
+ },
537
+ subscribeSensors: (type, callback) => {
538
+ if (!subscribers[type]) {
539
+ subscribers[type] = [];
540
+ }
541
+ subscribers[type].unshift(callback);
542
+ return () => {
543
+ const listeners = subscribers[type];
544
+ if (listeners) {
545
+ listeners.splice(0, listeners.length, ...listeners.filter((el) => el !== callback));
546
+ }
547
+ };
548
+ },
549
+ };
550
+ }, [subscribers]);
551
+ }
552
+
553
+ function useThrottle(callback, delay) {
554
+ const lastCallbackTime = React.useRef(0);
555
+ const delayCallback = useDelay();
556
+ const executeCallback = useEventCallback((...args) => {
557
+ lastCallbackTime.current = Date.now();
558
+ callback(args);
559
+ });
560
+ return React.useCallback((...args) => {
561
+ delayCallback(() => {
562
+ executeCallback(args);
563
+ }, delay - (Date.now() - lastCallbackTime.current));
564
+ }, [delay, executeCallback, delayCallback]);
565
+ }
566
+
567
+ const slidePrefix = makeComposePrefix("slide");
568
+ const slideImagePrefix = makeComposePrefix("slide_image");
569
+ function ImageSlide({ slide: image, offset, render, rect, imageFit, onClick, onLoad, style }) {
570
+ var _a, _b, _c, _d, _e, _f, _g;
571
+ const [status, setStatus] = React.useState(SLIDE_STATUS_LOADING);
572
+ const { publish } = useEvents();
573
+ const { setTimeout } = useTimeouts();
574
+ const imageRef = React.useRef(null);
575
+ React.useEffect(() => {
576
+ if (offset === 0) {
577
+ publish(activeSlideStatus(status));
578
+ }
579
+ }, [offset, status, publish]);
580
+ const handleLoading = useEventCallback((img) => {
581
+ ("decode" in img ? img.decode() : Promise.resolve())
582
+ .catch(() => { })
583
+ .then(() => {
584
+ if (!img.parentNode) {
585
+ return;
586
+ }
587
+ setStatus(SLIDE_STATUS_COMPLETE);
588
+ setTimeout(() => {
589
+ onLoad === null || onLoad === void 0 ? void 0 : onLoad(img);
590
+ }, 0);
591
+ });
592
+ });
593
+ const setImageRef = React.useCallback((img) => {
594
+ imageRef.current = img;
595
+ if (img === null || img === void 0 ? void 0 : img.complete) {
596
+ handleLoading(img);
597
+ }
598
+ }, [handleLoading]);
599
+ const handleOnLoad = React.useCallback((event) => {
600
+ handleLoading(event.currentTarget);
601
+ }, [handleLoading]);
602
+ const onError = React.useCallback(() => {
603
+ setStatus(SLIDE_STATUS_ERROR);
604
+ }, []);
605
+ const cover = isImageFitCover(image, imageFit);
606
+ const nonInfinite = (value, fallback) => (Number.isFinite(value) ? value : fallback);
607
+ 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);
608
+ 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);
609
+ const defaultStyle = maxWidth && maxHeight
610
+ ? {
611
+ maxWidth: `min(${maxWidth}px, 100%)`,
612
+ maxHeight: `min(${maxHeight}px, 100%)`,
613
+ }
614
+ : {
615
+ maxWidth: "100%",
616
+ maxHeight: "100%",
617
+ };
618
+ 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(", ");
619
+ const estimateActualWidth = () => rect && !cover && image.width && image.height ? (rect.height / image.height) * image.width : Number.MAX_VALUE;
620
+ const sizes = srcSet && rect && hasWindow() ? `${Math.round(Math.min(estimateActualWidth(), rect.width))}px` : undefined;
621
+ return (React.createElement(React.Fragment, null,
622
+ React.createElement("img", { ref: setImageRef, onLoad: handleOnLoad, 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: { ...defaultStyle, ...style }, sizes: sizes, srcSet: srcSet, src: image.src }),
623
+ status !== SLIDE_STATUS_COMPLETE && (React.createElement("div", { className: cssClass(slidePrefix(SLIDE_STATUS_PLACEHOLDER)) },
624
+ status === SLIDE_STATUS_LOADING &&
625
+ ((render === null || render === void 0 ? void 0 : render.iconLoading) ? (render.iconLoading()) : (React.createElement(LoadingIcon, { className: clsx(cssClass(ELEMENT_ICON), cssClass(slidePrefix(SLIDE_STATUS_LOADING))) }))),
626
+ status === SLIDE_STATUS_ERROR &&
627
+ ((render === null || render === void 0 ? void 0 : render.iconError) ? (render.iconError()) : (React.createElement(ErrorIcon, { className: clsx(cssClass(ELEMENT_ICON), cssClass(slidePrefix(SLIDE_STATUS_ERROR))) })))))));
628
+ }
629
+
630
+ var SwipeState;
631
+ (function (SwipeState) {
632
+ SwipeState[SwipeState["NONE"] = 0] = "NONE";
633
+ SwipeState[SwipeState["SWIPE"] = 1] = "SWIPE";
634
+ SwipeState[SwipeState["ANIMATION"] = 2] = "ANIMATION";
635
+ })(SwipeState || (SwipeState = {}));
636
+
637
+ function usePointerEvents(subscribeSensors, onPointerDown, onPointerMove, onPointerUp, disabled) {
638
+ React.useEffect(() => {
639
+ if (disabled)
640
+ return () => { };
641
+ return cleanup(subscribeSensors(EVENT_ON_POINTER_DOWN, onPointerDown), subscribeSensors(EVENT_ON_POINTER_MOVE, onPointerMove), subscribeSensors(EVENT_ON_POINTER_UP, onPointerUp), subscribeSensors(EVENT_ON_POINTER_LEAVE, onPointerUp), subscribeSensors(EVENT_ON_POINTER_CANCEL, onPointerUp));
642
+ }, [subscribeSensors, onPointerDown, onPointerMove, onPointerUp, disabled]);
643
+ }
644
+
645
+ var Gesture;
646
+ (function (Gesture) {
647
+ Gesture[Gesture["NONE"] = 0] = "NONE";
648
+ Gesture[Gesture["SWIPE"] = 1] = "SWIPE";
649
+ Gesture[Gesture["PULL_DOWN"] = 2] = "PULL_DOWN";
650
+ })(Gesture || (Gesture = {}));
651
+ const SWIPE_THRESHOLD = 30;
652
+ function usePointerSwipe(subscribeSensors, isSwipeValid, containerWidth, swipeAnimationDuration, onSwipeStart, onSwipeProgress, onSwipeFinish, onSwipeCancel, onPullDownStart, onPullDownProgress, onPullDownFinish, onPullDownCancel) {
653
+ const offset = React.useRef(0);
654
+ const pointers = React.useRef([]);
655
+ const activePointer = React.useRef();
656
+ const startTime = React.useRef(0);
657
+ const gesture = React.useRef(Gesture.NONE);
658
+ const clearPointer = React.useCallback((event) => {
659
+ if (activePointer.current === event.pointerId) {
660
+ activePointer.current = undefined;
661
+ gesture.current = Gesture.NONE;
662
+ }
663
+ const currentPointers = pointers.current;
664
+ currentPointers.splice(0, currentPointers.length, ...currentPointers.filter((p) => p.pointerId !== event.pointerId));
665
+ }, []);
666
+ const addPointer = React.useCallback((event) => {
667
+ clearPointer(event);
668
+ event.persist();
669
+ pointers.current.push(event);
670
+ }, [clearPointer]);
671
+ const onPointerDown = useEventCallback((event) => {
672
+ addPointer(event);
673
+ });
674
+ const onPointerUp = useEventCallback((event) => {
675
+ if (pointers.current.find((x) => x.pointerId === event.pointerId) &&
676
+ activePointer.current === event.pointerId) {
677
+ const duration = Date.now() - startTime.current;
678
+ const currentOffset = offset.current;
679
+ if (gesture.current === Gesture.SWIPE) {
680
+ if (Math.abs(currentOffset) > 0.3 * containerWidth ||
681
+ (Math.abs(currentOffset) > 5 && duration < swipeAnimationDuration)) {
682
+ onSwipeFinish(currentOffset, duration);
683
+ }
684
+ else {
685
+ onSwipeCancel(currentOffset);
686
+ }
687
+ }
688
+ else if (gesture.current === Gesture.PULL_DOWN) {
689
+ if (currentOffset > 2 * SWIPE_THRESHOLD) {
690
+ onPullDownFinish(currentOffset, duration);
691
+ }
692
+ else {
693
+ onPullDownCancel(currentOffset);
694
+ }
695
+ }
696
+ offset.current = 0;
697
+ gesture.current = Gesture.NONE;
698
+ }
699
+ clearPointer(event);
700
+ });
701
+ const onPointerMove = useEventCallback((event) => {
702
+ const pointer = pointers.current.find((p) => p.pointerId === event.pointerId);
703
+ if (pointer) {
704
+ const isCurrentPointer = activePointer.current === event.pointerId;
705
+ if (event.buttons === 0) {
706
+ if (isCurrentPointer && offset.current !== 0) {
707
+ onPointerUp(event);
708
+ }
709
+ else {
710
+ clearPointer(pointer);
711
+ }
712
+ return;
713
+ }
714
+ const deltaX = event.clientX - pointer.clientX;
715
+ const deltaY = event.clientY - pointer.clientY;
716
+ if (activePointer.current === undefined) {
717
+ const startGesture = (newGesture) => {
718
+ addPointer(event);
719
+ activePointer.current = event.pointerId;
720
+ startTime.current = Date.now();
721
+ gesture.current = newGesture;
722
+ };
723
+ if (Math.abs(deltaX) > Math.abs(deltaY) && Math.abs(deltaX) > SWIPE_THRESHOLD && isSwipeValid(deltaX)) {
724
+ startGesture(Gesture.SWIPE);
725
+ onSwipeStart();
726
+ }
727
+ else if (Math.abs(deltaY) > Math.abs(deltaX) && Math.abs(deltaY) > SWIPE_THRESHOLD) {
728
+ startGesture(Gesture.PULL_DOWN);
729
+ onPullDownStart();
730
+ }
731
+ }
732
+ else if (isCurrentPointer) {
733
+ if (gesture.current === Gesture.SWIPE) {
734
+ offset.current = deltaX;
735
+ onSwipeProgress(deltaX);
736
+ }
737
+ else if (gesture.current === Gesture.PULL_DOWN) {
738
+ offset.current = deltaY;
739
+ onPullDownProgress(deltaY);
740
+ }
741
+ }
742
+ }
743
+ });
744
+ usePointerEvents(subscribeSensors, onPointerDown, onPointerMove, onPointerUp);
745
+ }
746
+
747
+ const WHEEL = "wheel";
748
+ function preventDefault(event) {
749
+ if (Math.abs(event.deltaX) > Math.abs(event.deltaY) || event.ctrlKey) {
750
+ event.preventDefault();
751
+ }
752
+ }
753
+ function usePreventSwipeNavigation() {
754
+ const ref = React.useRef(null);
755
+ return React.useCallback((node) => {
756
+ var _a;
757
+ if (node) {
758
+ node.addEventListener(WHEEL, preventDefault, { passive: false });
759
+ }
760
+ else {
761
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.removeEventListener(WHEEL, preventDefault);
762
+ }
763
+ ref.current = node;
764
+ }, []);
765
+ }
766
+
767
+ function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidth, swipeAnimationDuration, onSwipeStart, onSwipeProgress, onSwipeFinish, onSwipeCancel) {
768
+ const offset = React.useRef(0);
769
+ const intent = React.useRef(0);
770
+ const intentCleanup = React.useRef();
771
+ const resetCleanup = React.useRef();
772
+ const wheelResidualMomentum = React.useRef(0);
773
+ const startTime = React.useRef(0);
774
+ const { setTimeout, clearTimeout } = useTimeouts();
775
+ const cancelSwipeIntentCleanup = React.useCallback(() => {
776
+ if (intentCleanup.current) {
777
+ clearTimeout(intentCleanup.current);
778
+ intentCleanup.current = undefined;
779
+ }
780
+ }, [clearTimeout]);
781
+ const cancelSwipeResetCleanup = React.useCallback(() => {
782
+ if (resetCleanup.current) {
783
+ clearTimeout(resetCleanup.current);
784
+ resetCleanup.current = undefined;
785
+ }
786
+ }, [clearTimeout]);
787
+ const handleCleanup = useEventCallback(() => {
788
+ if (swipeState !== SwipeState.SWIPE) {
789
+ offset.current = 0;
790
+ startTime.current = 0;
791
+ cancelSwipeIntentCleanup();
792
+ cancelSwipeResetCleanup();
793
+ }
794
+ });
795
+ React.useEffect(handleCleanup, [swipeState, handleCleanup]);
796
+ const handleCancelSwipe = useEventCallback((currentSwipeOffset) => {
797
+ resetCleanup.current = undefined;
798
+ if (offset.current === currentSwipeOffset) {
799
+ onSwipeCancel(offset.current);
800
+ }
801
+ });
802
+ const onWheel = useEventCallback((event) => {
803
+ if (event.ctrlKey) {
804
+ return;
805
+ }
806
+ if (Math.abs(event.deltaY) > Math.abs(event.deltaX)) {
807
+ return;
808
+ }
809
+ if (!swipeState) {
810
+ if (Math.abs(event.deltaX) <= 1.2 * Math.abs(wheelResidualMomentum.current)) {
811
+ wheelResidualMomentum.current = event.deltaX;
812
+ return;
813
+ }
814
+ if (!isSwipeValid(-event.deltaX)) {
815
+ return;
816
+ }
817
+ intent.current += event.deltaX;
818
+ cancelSwipeIntentCleanup();
819
+ if (Math.abs(intent.current) > 30) {
820
+ intent.current = 0;
821
+ wheelResidualMomentum.current = 0;
822
+ startTime.current = Date.now();
823
+ onSwipeStart();
824
+ }
825
+ else {
826
+ const currentSwipeIntent = intent.current;
827
+ intentCleanup.current = setTimeout(() => {
828
+ intentCleanup.current = undefined;
829
+ if (currentSwipeIntent === intent.current) {
830
+ intent.current = 0;
831
+ }
832
+ }, swipeAnimationDuration);
833
+ }
834
+ }
835
+ else if (swipeState === SwipeState.SWIPE) {
836
+ let newSwipeOffset = offset.current - event.deltaX;
837
+ newSwipeOffset = Math.min(Math.abs(newSwipeOffset), containerWidth) * Math.sign(newSwipeOffset);
838
+ offset.current = newSwipeOffset;
839
+ onSwipeProgress(newSwipeOffset);
840
+ cancelSwipeResetCleanup();
841
+ if (Math.abs(newSwipeOffset) > 0.2 * containerWidth) {
842
+ wheelResidualMomentum.current = event.deltaX;
843
+ onSwipeFinish(newSwipeOffset, Date.now() - startTime.current);
844
+ return;
845
+ }
846
+ resetCleanup.current = setTimeout(() => handleCancelSwipe(newSwipeOffset), 2 * swipeAnimationDuration);
847
+ }
848
+ else {
849
+ wheelResidualMomentum.current = event.deltaX;
850
+ }
851
+ });
852
+ React.useEffect(() => subscribeSensors(EVENT_ON_WHEEL, onWheel), [subscribeSensors, onWheel]);
853
+ }
854
+
855
+ const cssContainerPrefix = makeComposePrefix("container");
856
+ const ControllerContext = React.createContext(null);
857
+ const useController = makeUseContext("useController", "ControllerContext", ControllerContext);
858
+ function Controller({ children, ...props }) {
859
+ var _a;
860
+ const { carousel, animation, controller, on, styles, render } = props;
861
+ const [toolbarWidth, setToolbarWidth] = React.useState();
862
+ const state = useLightboxState();
863
+ const dispatch = useLightboxDispatch();
864
+ const [swipeState, setSwipeState] = React.useState(SwipeState.NONE);
865
+ const swipeOffset = React.useRef(0);
866
+ const { registerSensors, subscribeSensors } = useSensors();
867
+ const { subscribe, publish } = useEvents();
868
+ const cleanupAnimationIncrement = useDelay();
869
+ const cleanupSwipeOffset = useDelay();
870
+ const { containerRef, setContainerRef, containerRect } = useContainerRect();
871
+ const handleContainerRef = useForkRef(usePreventSwipeNavigation(), setContainerRef);
872
+ const carouselRef = React.useRef(null);
873
+ const setCarouselRef = useForkRef(carouselRef, undefined);
874
+ const isRTL = useRTL();
875
+ const rtl = (value) => (isRTL ? -1 : 1) * (typeof value === "number" ? value : 1);
876
+ const focus = useEventCallback(() => { var _a; return (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.focus(); });
877
+ const getLightboxProps = useEventCallback(() => props);
878
+ const getLightboxState = useEventCallback(() => state);
879
+ const prev = React.useCallback((params) => publish(ACTION_PREV, params), [publish]);
880
+ const next = React.useCallback((params) => publish(ACTION_NEXT, params), [publish]);
881
+ const close = React.useCallback(() => publish(ACTION_CLOSE), [publish]);
882
+ const isSwipeValid = (offset) => !(carousel.finite &&
883
+ ((rtl(offset) > 0 && state.currentIndex === 0) ||
884
+ (rtl(offset) < 0 && state.currentIndex === state.slides.length - 1)));
885
+ const setSwipeOffset = (offset) => {
886
+ var _a;
887
+ swipeOffset.current = offset;
888
+ (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.style.setProperty(cssVar("swipe_offset"), `${Math.round(offset)}px`);
889
+ };
890
+ const { prepareAnimation, isAnimationPlaying } = useAnimation(carouselRef, (snapshot, rect, translate) => {
891
+ var _a;
892
+ if (carouselRef.current && containerRect && ((_a = state.animation) === null || _a === void 0 ? void 0 : _a.duration)) {
893
+ const parsedSpacing = parseLengthPercentage(carousel.spacing);
894
+ const spacingValue = (parsedSpacing.percent
895
+ ? (parsedSpacing.percent * containerRect.width) / 100
896
+ : parsedSpacing.pixel) || 0;
897
+ return {
898
+ keyframes: [
899
+ {
900
+ transform: `translateX(${rtl(state.globalIndex - snapshot.index) * (containerRect.width + spacingValue) +
901
+ snapshot.rect.x -
902
+ rect.x +
903
+ translate.x}px)`,
904
+ },
905
+ { transform: "translateX(0)" },
906
+ ],
907
+ duration: state.animation.duration,
908
+ easing: state.animation.easing,
909
+ };
910
+ }
911
+ return undefined;
912
+ });
913
+ const swipe = useEventCallback((action) => {
914
+ var _a, _b;
915
+ const currentSwipeOffset = action.offset || 0;
916
+ const swipeDuration = !currentSwipeOffset ? (_a = animation.navigation) !== null && _a !== void 0 ? _a : animation.swipe : animation.swipe;
917
+ const swipeEasing = !currentSwipeOffset && !isAnimationPlaying() ? animation.easing.navigation : animation.easing.swipe;
918
+ let { direction } = action;
919
+ const count = (_b = action.count) !== null && _b !== void 0 ? _b : 1;
920
+ let newSwipeState = SwipeState.ANIMATION;
921
+ let newSwipeAnimationDuration = swipeDuration * count;
922
+ if (!direction) {
923
+ const containerWidth = containerRect === null || containerRect === void 0 ? void 0 : containerRect.width;
924
+ const elapsedTime = action.duration || 0;
925
+ const expectedTime = containerWidth
926
+ ? (swipeDuration / containerWidth) * Math.abs(currentSwipeOffset)
927
+ : swipeDuration;
928
+ if (count !== 0) {
929
+ if (elapsedTime < expectedTime) {
930
+ newSwipeAnimationDuration =
931
+ (newSwipeAnimationDuration / expectedTime) * Math.max(elapsedTime, expectedTime / 5);
932
+ }
933
+ else if (containerWidth) {
934
+ newSwipeAnimationDuration =
935
+ (swipeDuration / containerWidth) * (containerWidth - Math.abs(currentSwipeOffset));
936
+ }
937
+ direction = rtl(currentSwipeOffset) > 0 ? ACTION_PREV : ACTION_NEXT;
938
+ }
939
+ else {
940
+ newSwipeAnimationDuration = swipeDuration / 2;
941
+ }
942
+ }
943
+ let increment = 0;
944
+ if (direction === ACTION_PREV) {
945
+ if (isSwipeValid(rtl(1))) {
946
+ increment = -count;
947
+ }
948
+ else {
949
+ newSwipeState = SwipeState.NONE;
950
+ newSwipeAnimationDuration = swipeDuration;
951
+ }
952
+ }
953
+ else if (direction === ACTION_NEXT) {
954
+ if (isSwipeValid(rtl(-1))) {
955
+ increment = count;
956
+ }
957
+ else {
958
+ newSwipeState = SwipeState.NONE;
959
+ newSwipeAnimationDuration = swipeDuration;
960
+ }
961
+ }
962
+ newSwipeAnimationDuration = Math.round(newSwipeAnimationDuration);
963
+ cleanupSwipeOffset(() => {
964
+ setSwipeOffset(0);
965
+ setSwipeState(SwipeState.NONE);
966
+ }, newSwipeAnimationDuration);
967
+ if (carouselRef.current) {
968
+ prepareAnimation({
969
+ rect: carouselRef.current.getBoundingClientRect(),
970
+ index: state.globalIndex,
971
+ });
972
+ }
973
+ setSwipeState(newSwipeState);
974
+ publish(ACTION_SWIPE, {
975
+ type: "swipe",
976
+ increment,
977
+ duration: newSwipeAnimationDuration,
978
+ easing: swipeEasing,
979
+ });
980
+ });
981
+ React.useEffect(() => {
982
+ var _a, _b;
983
+ if (((_a = state.animation) === null || _a === void 0 ? void 0 : _a.increment) && ((_b = state.animation) === null || _b === void 0 ? void 0 : _b.duration)) {
984
+ cleanupAnimationIncrement(() => dispatch({ type: "swipe", increment: 0 }), state.animation.duration);
985
+ }
986
+ }, [state.animation, dispatch, cleanupAnimationIncrement]);
987
+ const swipeParams = [
988
+ subscribeSensors,
989
+ isSwipeValid,
990
+ (containerRect === null || containerRect === void 0 ? void 0 : containerRect.width) || 0,
991
+ animation.swipe,
992
+ () => setSwipeState(SwipeState.SWIPE),
993
+ (offset) => setSwipeOffset(offset),
994
+ (offset, duration) => swipe({ offset, duration, count: 1 }),
995
+ (offset) => swipe({ offset, count: 0 }),
996
+ ];
997
+ const pullDownParams = [
998
+ () => { },
999
+ () => { },
1000
+ () => {
1001
+ if (controller.closeOnPullDown) {
1002
+ close();
1003
+ }
1004
+ },
1005
+ () => { },
1006
+ ];
1007
+ usePointerSwipe(...swipeParams, ...pullDownParams);
1008
+ useWheelSwipe(swipeState, ...swipeParams);
1009
+ const focusOnMount = useEventCallback(() => {
1010
+ var _a;
1011
+ if (controller.focus) {
1012
+ (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
1013
+ }
1014
+ });
1015
+ React.useEffect(focusOnMount, [focusOnMount]);
1016
+ const onViewCallback = useEventCallback(() => {
1017
+ var _a;
1018
+ (_a = on.view) === null || _a === void 0 ? void 0 : _a.call(on, { index: state.currentIndex });
1019
+ });
1020
+ React.useEffect(onViewCallback, [state.globalIndex, onViewCallback]);
1021
+ React.useEffect(() => cleanup(subscribe(ACTION_PREV, (action) => swipe({ direction: ACTION_PREV, ...action })), subscribe(ACTION_NEXT, (action) => swipe({ direction: ACTION_NEXT, ...action })), subscribe(ACTION_SWIPE, (action) => dispatch(action))), [subscribe, swipe, dispatch]);
1022
+ React.useEffect(() => subscribeSensors(EVENT_ON_KEY_UP, (event) => {
1023
+ if (event.code === VK_ESCAPE) {
1024
+ close();
1025
+ }
1026
+ }), [subscribeSensors, close]);
1027
+ const context = React.useMemo(() => ({
1028
+ prev,
1029
+ next,
1030
+ close,
1031
+ focus,
1032
+ slideRect: containerRect ? computeSlideRect(containerRect, carousel.padding) : { width: 0, height: 0 },
1033
+ containerRect: containerRect || { width: 0, height: 0 },
1034
+ subscribeSensors,
1035
+ containerRef,
1036
+ setCarouselRef,
1037
+ toolbarWidth,
1038
+ setToolbarWidth,
1039
+ }), [
1040
+ prev,
1041
+ next,
1042
+ close,
1043
+ focus,
1044
+ subscribeSensors,
1045
+ containerRect,
1046
+ containerRef,
1047
+ setCarouselRef,
1048
+ toolbarWidth,
1049
+ setToolbarWidth,
1050
+ carousel.padding,
1051
+ ]);
1052
+ React.useImperativeHandle(controller.ref, () => ({
1053
+ prev,
1054
+ next,
1055
+ close,
1056
+ focus,
1057
+ getLightboxProps,
1058
+ getLightboxState,
1059
+ }), [prev, next, close, focus, getLightboxProps, getLightboxState]);
1060
+ return (React.createElement("div", { ref: handleContainerRef, className: clsx(cssClass(cssContainerPrefix()), cssClass(CLASS_FLEX_CENTER)), style: {
1061
+ ...(swipeState === SwipeState.SWIPE
1062
+ ? { [cssVar("swipe_offset")]: `${Math.round(swipeOffset.current)}px` }
1063
+ : null),
1064
+ ...(controller.touchAction !== "none"
1065
+ ? { [cssVar("controller_touch_action")]: controller.touchAction }
1066
+ : null),
1067
+ ...styles.container,
1068
+ }, ...(controller.aria ? { role: "presentation", "aria-live": "polite" } : null), tabIndex: -1, ...registerSensors }, containerRect && (React.createElement(ControllerContext.Provider, { value: context },
1069
+ children, (_a = render.controls) === null || _a === void 0 ? void 0 :
1070
+ _a.call(render)))));
1071
+ }
1072
+ const ControllerModule = createModule(MODULE_CONTROLLER, Controller);
1073
+
1074
+ function cssPrefix$2(value) {
1075
+ return composePrefix(MODULE_CAROUSEL, value);
1076
+ }
1077
+ function cssSlidePrefix(value) {
1078
+ return composePrefix("slide", value);
1079
+ }
1080
+ function CarouselSlide({ slide, offset }) {
1081
+ const containerRef = React.useRef(null);
1082
+ const { currentIndex } = useLightboxState();
1083
+ const { slideRect, close } = useController();
1084
+ const { render, carousel: { imageFit }, on: { click: onClick }, controller: { closeOnBackdropClick }, } = useLightboxProps();
1085
+ const renderSlide = () => {
1086
+ var _a, _b, _c, _d;
1087
+ let rendered = (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, { slide, offset, rect: slideRect });
1088
+ if (!rendered && isImageSlide(slide)) {
1089
+ rendered = (React.createElement(ImageSlide, { slide: slide, offset: offset, render: render, rect: slideRect, imageFit: imageFit, onClick: offset === 0 ? () => onClick === null || onClick === void 0 ? void 0 : onClick({ index: currentIndex }) : undefined }));
1090
+ }
1091
+ return rendered ? (React.createElement(React.Fragment, null, (_b = render.slideHeader) === null || _b === void 0 ? void 0 :
1092
+ _b.call(render, { slide }),
1093
+ ((_c = render.slideContainer) !== null && _c !== void 0 ? _c : (({ children }) => children))({ slide, children: rendered }), (_d = render.slideFooter) === null || _d === void 0 ? void 0 :
1094
+ _d.call(render, { slide }))) : null;
1095
+ };
1096
+ const handleBackdropClick = (event) => {
1097
+ const container = containerRef.current;
1098
+ const target = event.target instanceof HTMLElement ? event.target : undefined;
1099
+ if (closeOnBackdropClick &&
1100
+ target &&
1101
+ container &&
1102
+ (target === container ||
1103
+ (Array.from(container.children).find((x) => x === target) &&
1104
+ target.classList.contains(cssClass(CLASS_FULLSIZE))))) {
1105
+ close();
1106
+ }
1107
+ };
1108
+ return (React.createElement("div", { ref: containerRef, className: clsx(cssClass(cssSlidePrefix()), offset === 0 && cssClass(cssSlidePrefix("current")), cssClass(CLASS_FLEX_CENTER)), onClick: handleBackdropClick }, renderSlide()));
1109
+ }
1110
+ function Placeholder() {
1111
+ return React.createElement("div", { className: cssClass("slide") });
1112
+ }
1113
+ function Carousel({ carousel: { finite, preload, padding, spacing } }) {
1114
+ const { slides, currentIndex, globalIndex } = useLightboxState();
1115
+ const { setCarouselRef } = useController();
1116
+ const spacingValue = parseLengthPercentage(spacing);
1117
+ const paddingValue = parseLengthPercentage(padding);
1118
+ const items = [];
1119
+ if ((slides === null || slides === void 0 ? void 0 : slides.length) > 0) {
1120
+ for (let i = currentIndex - preload; i < currentIndex; i += 1) {
1121
+ const key = globalIndex + i - currentIndex;
1122
+ items.push(!finite || i >= 0 ? (React.createElement(CarouselSlide, { key: key, slide: slides[(i + preload * slides.length) % slides.length], offset: i - currentIndex })) : (React.createElement(Placeholder, { key: key })));
1123
+ }
1124
+ items.push(React.createElement(CarouselSlide, { key: globalIndex, slide: slides[currentIndex], offset: 0 }));
1125
+ for (let i = currentIndex + 1; i <= currentIndex + preload; i += 1) {
1126
+ const key = globalIndex + i - currentIndex;
1127
+ items.push(!finite || i <= slides.length - 1 ? (React.createElement(CarouselSlide, { key: key, slide: slides[i % slides.length], offset: i - currentIndex })) : (React.createElement(Placeholder, { key: key })));
1128
+ }
1129
+ }
1130
+ return (React.createElement("div", { ref: setCarouselRef, className: clsx(cssClass(cssPrefix$2()), items.length > 0 && cssClass(cssPrefix$2("with_slides"))), style: {
1131
+ [`${cssVar(cssPrefix$2("slides_count"))}`]: items.length,
1132
+ [`${cssVar(cssPrefix$2("spacing_px"))}`]: spacingValue.pixel || 0,
1133
+ [`${cssVar(cssPrefix$2("spacing_percent"))}`]: spacingValue.percent || 0,
1134
+ [`${cssVar(cssPrefix$2("padding_px"))}`]: paddingValue.pixel || 0,
1135
+ [`${cssVar(cssPrefix$2("padding_percent"))}`]: paddingValue.percent || 0,
1136
+ } }, items));
1137
+ }
1138
+ const CarouselModule = createModule(MODULE_CAROUSEL, Carousel);
1139
+
1140
+ function NavigationButton({ label, icon, renderIcon, action, onClick, disabled }) {
1141
+ return (React.createElement(IconButton, { label: label, icon: icon, renderIcon: renderIcon, className: cssClass(`navigation_${action}`), disabled: disabled, onClick: onClick, ...useLoseFocus(useController().focus, disabled) }));
1142
+ }
1143
+ function Navigation({ carousel: { finite }, animation, render: { buttonPrev, buttonNext, iconPrev, iconNext }, }) {
1144
+ var _a;
1145
+ const { slides, currentIndex } = useLightboxState();
1146
+ const { prev, next, subscribeSensors } = useController();
1147
+ const isRTL = useRTL();
1148
+ const prevDisabled = slides.length === 0 || (finite && currentIndex === 0);
1149
+ const nextDisabled = slides.length === 0 || (finite && currentIndex === slides.length - 1);
1150
+ const throttle = ((_a = animation.navigation) !== null && _a !== void 0 ? _a : animation.swipe) / 2;
1151
+ const prevThrottled = useThrottle(prev, throttle);
1152
+ const nextThrottled = useThrottle(next, throttle);
1153
+ const handleKeyDown = useEventCallback((event) => {
1154
+ if (event.key === VK_ARROW_LEFT && !(isRTL ? nextDisabled : prevDisabled)) {
1155
+ (isRTL ? nextThrottled : prevThrottled)();
1156
+ }
1157
+ if (event.key === VK_ARROW_RIGHT && !(isRTL ? prevDisabled : nextDisabled)) {
1158
+ (isRTL ? prevThrottled : nextThrottled)();
1159
+ }
1160
+ });
1161
+ React.useEffect(() => subscribeSensors(EVENT_ON_KEY_DOWN, handleKeyDown), [subscribeSensors, handleKeyDown]);
1162
+ return (React.createElement(React.Fragment, null,
1163
+ buttonPrev ? (buttonPrev()) : (React.createElement(NavigationButton, { label: "Previous", action: ACTION_PREV, icon: PreviousIcon, renderIcon: iconPrev, disabled: prevDisabled, onClick: prev })),
1164
+ buttonNext ? (buttonNext()) : (React.createElement(NavigationButton, { label: "Next", action: ACTION_NEXT, icon: NextIcon, renderIcon: iconNext, disabled: nextDisabled, onClick: next }))));
1165
+ }
1166
+ const NavigationModule = createModule(MODULE_NAVIGATION, Navigation);
1167
+
1168
+ const noScroll = cssClass(CLASS_NO_SCROLL);
1169
+ const noScrollPadding = cssClass(CLASS_NO_SCROLL_PADDING);
1170
+ function isHTMLElement(element) {
1171
+ return "style" in element;
1172
+ }
1173
+ function padScrollbar(element, padding, rtl) {
1174
+ const styles = window.getComputedStyle(element);
1175
+ const property = rtl ? "padding-left" : "padding-right";
1176
+ const computedValue = rtl ? styles.paddingLeft : styles.paddingRight;
1177
+ const originalValue = element.style.getPropertyValue(property);
1178
+ element.style.setProperty(property, `${(parseInt(computedValue, 10) || 0) + padding}px`);
1179
+ return () => {
1180
+ if (originalValue) {
1181
+ element.style.setProperty(property, originalValue);
1182
+ }
1183
+ else {
1184
+ element.style.removeProperty(property);
1185
+ }
1186
+ };
1187
+ }
1188
+ function NoScroll({ children }) {
1189
+ const rtl = useRTL();
1190
+ useLayoutEffect(() => {
1191
+ const cleanup = [];
1192
+ const { body, documentElement } = document;
1193
+ const scrollbar = Math.round(window.innerWidth - documentElement.clientWidth);
1194
+ if (scrollbar > 0) {
1195
+ cleanup.push(padScrollbar(body, scrollbar, rtl));
1196
+ const elements = body.getElementsByTagName("*");
1197
+ for (let i = 0; i < elements.length; i += 1) {
1198
+ const element = elements[i];
1199
+ if (isHTMLElement(element) &&
1200
+ window.getComputedStyle(element).getPropertyValue("position") === "fixed" &&
1201
+ !element.classList.contains(noScrollPadding)) {
1202
+ cleanup.push(padScrollbar(element, scrollbar, rtl));
1203
+ }
1204
+ }
1205
+ }
1206
+ body.classList.add(noScroll);
1207
+ return () => {
1208
+ body.classList.remove(noScroll);
1209
+ cleanup.forEach((clean) => clean());
1210
+ };
1211
+ }, [rtl]);
1212
+ return React.createElement(React.Fragment, null, children);
1213
+ }
1214
+ const NoScrollModule = createModule(MODULE_NO_SCROLL, NoScroll);
1215
+
1216
+ function cssPrefix$1(value) {
1217
+ return composePrefix(MODULE_PORTAL, value);
1218
+ }
1219
+ function setAttribute(element, attribute, value) {
1220
+ const previousValue = element.getAttribute(attribute);
1221
+ element.setAttribute(attribute, value);
1222
+ return () => {
1223
+ if (previousValue) {
1224
+ element.setAttribute(attribute, previousValue);
1225
+ }
1226
+ else {
1227
+ element.removeAttribute(attribute);
1228
+ }
1229
+ };
1230
+ }
1231
+ function Portal({ children, animation, styles, className, on, portal, close }) {
1232
+ const [mounted, setMounted] = React.useState(false);
1233
+ const [visible, setVisible] = React.useState(false);
1234
+ const cleanup = React.useRef([]);
1235
+ const { setTimeout } = useTimeouts();
1236
+ const { subscribe } = useEvents();
1237
+ const reduceMotion = useMotionPreference();
1238
+ const animationDuration = !reduceMotion ? animation.fade : 0;
1239
+ React.useEffect(() => {
1240
+ setMounted(true);
1241
+ return () => {
1242
+ setMounted(false);
1243
+ setVisible(false);
1244
+ };
1245
+ }, []);
1246
+ const handleClose = useEventCallback(() => {
1247
+ var _a;
1248
+ setVisible(false);
1249
+ (_a = on.exiting) === null || _a === void 0 ? void 0 : _a.call(on);
1250
+ setTimeout(() => {
1251
+ var _a;
1252
+ (_a = on.exited) === null || _a === void 0 ? void 0 : _a.call(on);
1253
+ close();
1254
+ }, animationDuration);
1255
+ });
1256
+ React.useEffect(() => subscribe(ACTION_CLOSE, handleClose), [subscribe, handleClose]);
1257
+ const handleEnter = useEventCallback((node) => {
1258
+ var _a, _b, _c;
1259
+ node.scrollTop;
1260
+ setVisible(true);
1261
+ (_a = on.entering) === null || _a === void 0 ? void 0 : _a.call(on);
1262
+ const elements = (_c = (_b = node.parentNode) === null || _b === void 0 ? void 0 : _b.children) !== null && _c !== void 0 ? _c : [];
1263
+ for (let i = 0; i < elements.length; i += 1) {
1264
+ const element = elements[i];
1265
+ if (["TEMPLATE", "SCRIPT", "STYLE"].indexOf(element.tagName) === -1 && element !== node) {
1266
+ cleanup.current.push(setAttribute(element, "inert", "true"));
1267
+ cleanup.current.push(setAttribute(element, "aria-hidden", "true"));
1268
+ }
1269
+ }
1270
+ setTimeout(() => {
1271
+ var _a;
1272
+ (_a = on.entered) === null || _a === void 0 ? void 0 : _a.call(on);
1273
+ }, animationDuration);
1274
+ });
1275
+ const handleExit = useEventCallback(() => {
1276
+ cleanup.current.forEach((clean) => clean());
1277
+ cleanup.current = [];
1278
+ });
1279
+ const handleRef = React.useCallback((node) => {
1280
+ if (node) {
1281
+ handleEnter(node);
1282
+ }
1283
+ else {
1284
+ handleExit();
1285
+ }
1286
+ }, [handleEnter, handleExit]);
1287
+ return mounted
1288
+ ? createPortal(React.createElement("div", { ref: handleRef, className: clsx(className, cssClass("root"), cssClass(cssPrefix$1()), cssClass(CLASS_NO_SCROLL_PADDING), visible && cssClass(cssPrefix$1("open"))), role: "presentation", "aria-live": "polite", style: {
1289
+ ...(animation.fade !== LightboxDefaultProps.animation.fade
1290
+ ? { [cssVar("fade_animation_duration")]: `${animationDuration}ms` }
1291
+ : null),
1292
+ ...(animation.easing.fade !== LightboxDefaultProps.animation.easing.fade
1293
+ ? { [cssVar("fade_animation_timing_function")]: animation.easing.fade }
1294
+ : null),
1295
+ ...styles.root,
1296
+ } }, children), portal.root || document.body)
1297
+ : null;
1298
+ }
1299
+ const PortalModule = createModule(MODULE_PORTAL, Portal);
1300
+
1301
+ function Root({ children }) {
1302
+ return React.createElement(React.Fragment, null, children);
1303
+ }
1304
+ const RootModule = createModule(MODULE_ROOT, Root);
1305
+
1306
+ function cssPrefix(value) {
1307
+ return composePrefix(MODULE_TOOLBAR, value);
1308
+ }
1309
+ function Toolbar({ toolbar: { buttons }, render: { buttonClose, iconClose } }) {
1310
+ const { close, setToolbarWidth } = useController();
1311
+ const { setContainerRef, containerRect } = useContainerRect();
1312
+ useLayoutEffect(() => {
1313
+ setToolbarWidth(containerRect === null || containerRect === void 0 ? void 0 : containerRect.width);
1314
+ }, [setToolbarWidth, containerRect === null || containerRect === void 0 ? void 0 : containerRect.width]);
1315
+ const renderCloseButton = () => {
1316
+ if (buttonClose)
1317
+ return buttonClose();
1318
+ return React.createElement(IconButton, { key: ACTION_CLOSE, label: "Close", icon: CloseIcon, renderIcon: iconClose, onClick: close });
1319
+ };
1320
+ return (React.createElement("div", { ref: setContainerRef, className: cssClass(cssPrefix()), ...stopNavigationEventsPropagation() }, buttons === null || buttons === void 0 ? void 0 : buttons.map((button) => (button === ACTION_CLOSE ? renderCloseButton() : button))));
1321
+ }
1322
+ const ToolbarModule = createModule(MODULE_TOOLBAR, Toolbar);
1323
+
1324
+ function renderNode(node, props) {
1325
+ var _a;
1326
+ 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)));
1327
+ }
1328
+ function mergeAnimation(defaultAnimation, animation = {}) {
1329
+ const { easing: defaultAnimationEasing, ...restDefaultAnimation } = defaultAnimation;
1330
+ const { easing, ...restAnimation } = animation;
1331
+ return {
1332
+ easing: { ...defaultAnimationEasing, ...easing },
1333
+ ...restDefaultAnimation,
1334
+ ...restAnimation,
1335
+ };
1336
+ }
1337
+ function Lightbox({ carousel, animation, render, toolbar, controller, on, plugins, slides, index, ...restProps }) {
1338
+ const { animation: defaultAnimation, carousel: defaultCarousel, render: defaultRender, toolbar: defaultToolbar, controller: defaultController, on: defaultOn, slides: defaultSlides, index: defaultIndex, plugins: defaultPlugins, ...restDefaultProps } = LightboxDefaultProps;
1339
+ const { config, augmentation } = withPlugins([
1340
+ createNode(PortalModule, [
1341
+ createNode(NoScrollModule, [
1342
+ createNode(ControllerModule, [
1343
+ createNode(CarouselModule),
1344
+ createNode(ToolbarModule),
1345
+ createNode(NavigationModule),
1346
+ ]),
1347
+ ]),
1348
+ ]),
1349
+ ], plugins || defaultPlugins);
1350
+ const props = augmentation({
1351
+ animation: mergeAnimation(defaultAnimation, animation),
1352
+ carousel: { ...defaultCarousel, ...carousel },
1353
+ render: { ...defaultRender, ...render },
1354
+ toolbar: { ...defaultToolbar, ...toolbar },
1355
+ controller: { ...defaultController, ...controller },
1356
+ on: { ...defaultOn, ...on },
1357
+ ...restDefaultProps,
1358
+ ...restProps,
1359
+ });
1360
+ if (!props.open)
1361
+ return null;
1362
+ return (React.createElement(LightboxPropsProvider, { ...props },
1363
+ React.createElement(LightboxStateProvider, { slides: slides || defaultSlides, index: index || defaultIndex },
1364
+ React.createElement(TimeoutsProvider, null,
1365
+ React.createElement(EventsProvider, null, renderNode(createNode(RootModule, config), props))))));
1366
+ }
1367
+
1368
+ export { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, CLASS_FLEX_CENTER, CLASS_FULLSIZE, CLASS_NO_SCROLL, CLASS_NO_SCROLL_PADDING, Carousel, CarouselModule, CloseIcon, Controller, ControllerContext, ControllerModule, 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, 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, TimeoutsContext, TimeoutsProvider, Toolbar, ToolbarModule, UNKNOWN_ACTION_TYPE, VK_ARROW_LEFT, VK_ARROW_RIGHT, VK_ESCAPE, activeSlideStatus, addToolbarButton, cleanup, clsx, composePrefix, computeSlideRect, createIcon, createIconDisabled, createModule, createNode, cssClass, cssVar, Lightbox as default, devicePixelRatio, getSlide, getSlideIfPresent, getSlideIndex, hasSlides, hasWindow, isImageFitCover, isImageSlide, label, makeComposePrefix, makeUseContext, parseLengthPercentage, round, setRef, stopNavigationEventsPropagation, useAnimation, useContainerRect, useController, useDelay, useEventCallback, useEvents, useForkRef, useLayoutEffect, useLightboxDispatch, useLightboxProps, useLightboxState, useLoseFocus, useMotionPreference, usePointerEvents, useRTL, useSensors, useThrottle, useTimeouts, withPlugins };