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