@atom63/ui-react 0.2.0-beta.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.
- package/README.md +121 -0
- package/dist/button-sktq-nvV.d.ts +13 -0
- package/dist/chunk-7VSPECOH.js +73 -0
- package/dist/chunk-7VSPECOH.js.map +1 -0
- package/dist/chunk-AJLHJRK6.js +11 -0
- package/dist/chunk-AJLHJRK6.js.map +1 -0
- package/dist/chunk-MXNO63TC.js +2745 -0
- package/dist/chunk-MXNO63TC.js.map +1 -0
- package/dist/chunk-STCXERLM.js +354 -0
- package/dist/chunk-STCXERLM.js.map +1 -0
- package/dist/destination-link-C9NKeKLe.d.ts +34 -0
- package/dist/index.d.ts +1605 -0
- package/dist/index.js +7337 -0
- package/dist/index.js.map +1 -0
- package/dist/layout/index.d.ts +196 -0
- package/dist/layout/index.js +500 -0
- package/dist/layout/index.js.map +1 -0
- package/dist/media/index.d.ts +208 -0
- package/dist/media/index.js +1498 -0
- package/dist/media/index.js.map +1 -0
- package/dist/media/media-lightbox/parts/index.d.ts +284 -0
- package/dist/media/media-lightbox/parts/index.js +5 -0
- package/dist/media/media-lightbox/parts/index.js.map +1 -0
- package/dist/theme/index.d.ts +350 -0
- package/dist/theme/index.js +1173 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/types-Dxe5IzjE.d.ts +145 -0
- package/package.json +188 -0
- package/src/components/accordion/accordion.css +196 -0
- package/src/components/alert/alert.css +189 -0
- package/src/components/alert-dialog/alert-dialog.css +205 -0
- package/src/components/autocomplete/autocomplete.css +240 -0
- package/src/components/avatar/avatar.css +147 -0
- package/src/components/badge/badge.css +223 -0
- package/src/components/breadcrumb/breadcrumb.css +99 -0
- package/src/components/button/button.css +594 -0
- package/src/components/button-group/button-group.css +412 -0
- package/src/components/calendar/calendar.css +271 -0
- package/src/components/card/card.css +421 -0
- package/src/components/carousel/carousel.css +163 -0
- package/src/components/checkbox/checkbox.css +113 -0
- package/src/components/collapsible/collapsible.css +59 -0
- package/src/components/command/command.css +226 -0
- package/src/components/connected-panel/connected-panel.css +437 -0
- package/src/components/copy-button/copy-button.css +57 -0
- package/src/components/dialog/dialog.css +221 -0
- package/src/components/drawer/drawer.css +265 -0
- package/src/components/empty/empty.css +145 -0
- package/src/components/feedback-state/feedback-state.css +141 -0
- package/src/components/field/field.css +260 -0
- package/src/components/form/form.css +32 -0
- package/src/components/frame/frame.css +115 -0
- package/src/components/hover-card/hover-card.css +80 -0
- package/src/components/input/input.css +291 -0
- package/src/components/input-otp/input-otp.css +145 -0
- package/src/components/item/item.css +216 -0
- package/src/components/kbd/kbd.css +72 -0
- package/src/components/label/label.css +37 -0
- package/src/components/load-more-trigger/load-more-trigger.css +109 -0
- package/src/components/marquee/marquee.css +79 -0
- package/src/components/menu/menu.css +216 -0
- package/src/components/menubar/menubar.css +67 -0
- package/src/components/navigation-menu/navigation-menu.css +275 -0
- package/src/components/pagination/pagination.css +86 -0
- package/src/components/panel-setting-button/panel-setting-button.css +76 -0
- package/src/components/popover/popover.css +89 -0
- package/src/components/preview-card/preview-card.css +69 -0
- package/src/components/progress/progress.css +70 -0
- package/src/components/radio/radio.css +115 -0
- package/src/components/resizable/resizable.css +99 -0
- package/src/components/scroll-area/scroll-area.css +130 -0
- package/src/components/scrollable-list/scrollable-list.css +144 -0
- package/src/components/segmented-control/segmented-control.css +235 -0
- package/src/components/select/select.css +261 -0
- package/src/components/separator/separator.css +43 -0
- package/src/components/sheet/sheet.css +209 -0
- package/src/components/sidebar/sidebar.css +728 -0
- package/src/components/sidebar-nav-tree/sidebar-nav-tree.css +179 -0
- package/src/components/skeleton/skeleton.css +42 -0
- package/src/components/slider/slider.css +124 -0
- package/src/components/switch/switch.css +149 -0
- package/src/components/table/table.css +183 -0
- package/src/components/tabs/tabs.css +416 -0
- package/src/components/text-ticker/text-ticker.css +139 -0
- package/src/components/textarea/textarea.css +122 -0
- package/src/components/toggle/toggle.css +185 -0
- package/src/components/toggle-group/toggle-group.css +102 -0
- package/src/components/tooltip/tooltip.css +133 -0
- package/src/media/media-lightbox/media-lightbox.css +171 -0
- package/src/styles/index.css +3 -0
- package/src/styles/recipes.css +70 -0
- package/src/styles/reset.css +22 -0
|
@@ -0,0 +1,1498 @@
|
|
|
1
|
+
import { useReducedMotion, Lightbox, supportsViewTransitions, preferCheapMediaTransition, runMediaViewTransition, useLightboxConfig, useLightboxState, useLightboxRefs, CHROME_IN, CHROME_OUT, CHROME_EXIT_OFFSET } from '../chunk-MXNO63TC.js';
|
|
2
|
+
export { DEFAULT_MEDIA_LIGHTBOX_LABELS } from '../chunk-MXNO63TC.js';
|
|
3
|
+
import '../chunk-7VSPECOH.js';
|
|
4
|
+
import { cn } from '../chunk-AJLHJRK6.js';
|
|
5
|
+
import { motion, AnimatePresence } from 'motion/react';
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import { memo, forwardRef, createContext, useRef, useEffect, useState, useCallback, useMemo, useContext } from 'react';
|
|
8
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
9
|
+
import { Plus, LoaderCircle, ZoomOut, ZoomIn, X, ChevronLeft, ChevronRight, Play, Maximize } from 'lucide-react';
|
|
10
|
+
import { Dialog } from '@base-ui/react/dialog';
|
|
11
|
+
|
|
12
|
+
function useIntersectionObserver(options = {}) {
|
|
13
|
+
const {
|
|
14
|
+
threshold = 0.1,
|
|
15
|
+
root = null,
|
|
16
|
+
rootMargin = "50px",
|
|
17
|
+
// Load content 50px before it enters viewport
|
|
18
|
+
freezeOnceVisible = false
|
|
19
|
+
} = options;
|
|
20
|
+
const elementRef = useRef(null);
|
|
21
|
+
const [isIntersecting, setIsIntersecting] = useState(false);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const element = elementRef.current;
|
|
24
|
+
if (!element) return;
|
|
25
|
+
const observer = new IntersectionObserver(
|
|
26
|
+
([entry]) => {
|
|
27
|
+
const isElementIntersecting = entry.isIntersecting;
|
|
28
|
+
setIsIntersecting(isElementIntersecting);
|
|
29
|
+
if (isElementIntersecting && freezeOnceVisible) {
|
|
30
|
+
observer.unobserve(element);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
{ threshold, root, rootMargin }
|
|
34
|
+
);
|
|
35
|
+
observer.observe(element);
|
|
36
|
+
return () => {
|
|
37
|
+
observer.disconnect();
|
|
38
|
+
};
|
|
39
|
+
}, [threshold, root, rootMargin, freezeOnceVisible]);
|
|
40
|
+
return [elementRef, isIntersecting];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/media/hooks/use-lazy-media.ts
|
|
44
|
+
function useLazyMedia(options = {}) {
|
|
45
|
+
const {
|
|
46
|
+
rootMargin = "100px",
|
|
47
|
+
// Start loading 100px before entering viewport
|
|
48
|
+
threshold = 0.1,
|
|
49
|
+
enabled = true
|
|
50
|
+
} = options;
|
|
51
|
+
const [hasLoaded, setHasLoaded] = useState(!enabled);
|
|
52
|
+
const [elementRef, isIntersecting] = useIntersectionObserver({
|
|
53
|
+
rootMargin,
|
|
54
|
+
threshold,
|
|
55
|
+
freezeOnceVisible: true
|
|
56
|
+
// Once visible, stay loaded
|
|
57
|
+
});
|
|
58
|
+
const shouldLoad = isIntersecting || hasLoaded;
|
|
59
|
+
const markAsLoaded = useCallback(() => {
|
|
60
|
+
setHasLoaded(true);
|
|
61
|
+
}, []);
|
|
62
|
+
return {
|
|
63
|
+
ref: elementRef,
|
|
64
|
+
shouldLoad,
|
|
65
|
+
isIntersecting,
|
|
66
|
+
hasLoaded,
|
|
67
|
+
markAsLoaded
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
var MOBILE_BREAKPOINT = 768;
|
|
71
|
+
function useIsMobile() {
|
|
72
|
+
const [isMobile, setIsMobile] = React.useState(void 0);
|
|
73
|
+
React.useEffect(() => {
|
|
74
|
+
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
|
75
|
+
const onChange = () => {
|
|
76
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
77
|
+
};
|
|
78
|
+
mql.addEventListener("change", onChange);
|
|
79
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
80
|
+
return () => mql.removeEventListener("change", onChange);
|
|
81
|
+
}, []);
|
|
82
|
+
return !!isMobile;
|
|
83
|
+
}
|
|
84
|
+
function Skeleton({ className }) {
|
|
85
|
+
return /* @__PURE__ */ jsx("div", { className: cn("bg-muted animate-pulse rounded-md", className) });
|
|
86
|
+
}
|
|
87
|
+
var animatedImagesCache = /* @__PURE__ */ new Set();
|
|
88
|
+
var IMAGE_REVEAL_INITIAL = { opacity: 0, scale: 1.02 };
|
|
89
|
+
var IMAGE_REVEAL_ANIMATE = { opacity: 1, scale: 1 };
|
|
90
|
+
var IMAGE_REVEAL_TRANSITION = {
|
|
91
|
+
duration: 0.4,
|
|
92
|
+
ease: [0.25, 0.46, 0.45, 0.94]
|
|
93
|
+
};
|
|
94
|
+
var clearImageAnimationCache = () => animatedImagesCache.clear();
|
|
95
|
+
var Image = ({
|
|
96
|
+
src,
|
|
97
|
+
alt,
|
|
98
|
+
className,
|
|
99
|
+
imageClassName,
|
|
100
|
+
aspectRatio = "16/9",
|
|
101
|
+
fallbackText = "No image provided",
|
|
102
|
+
errorText = "Failed to load image",
|
|
103
|
+
showSkeleton = true,
|
|
104
|
+
skeletonClassName,
|
|
105
|
+
containerClassName,
|
|
106
|
+
lazy = true,
|
|
107
|
+
rootMargin = "100px",
|
|
108
|
+
priority = false,
|
|
109
|
+
forceNoLazy = false,
|
|
110
|
+
onLoad,
|
|
111
|
+
onError,
|
|
112
|
+
decoding = "async",
|
|
113
|
+
fetchPriority = "auto",
|
|
114
|
+
...props
|
|
115
|
+
}) => {
|
|
116
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
117
|
+
const [hasError, setHasError] = useState(false);
|
|
118
|
+
const [imageSrc, setImageSrc] = useState(null);
|
|
119
|
+
const [imageDimensions, setImageDimensions] = useState(
|
|
120
|
+
null
|
|
121
|
+
);
|
|
122
|
+
const isMobile = useIsMobile();
|
|
123
|
+
const reducedMotion = useReducedMotion();
|
|
124
|
+
const shouldUseLazy = lazy && !priority && !forceNoLazy;
|
|
125
|
+
const { ref: lazyRef, shouldLoad } = useLazyMedia({
|
|
126
|
+
rootMargin: shouldUseLazy ? rootMargin : "0px",
|
|
127
|
+
// Reduce unnecessary triggering
|
|
128
|
+
enabled: shouldUseLazy
|
|
129
|
+
});
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (!src) {
|
|
132
|
+
setHasError(true);
|
|
133
|
+
setIsLoading(false);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (!shouldUseLazy || shouldLoad) {
|
|
137
|
+
if (imageSrc === src) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
setIsLoading(true);
|
|
141
|
+
setHasError(false);
|
|
142
|
+
const img = new window.Image();
|
|
143
|
+
if (decoding) {
|
|
144
|
+
img.decoding = decoding;
|
|
145
|
+
}
|
|
146
|
+
if (fetchPriority && "fetchPriority" in img) {
|
|
147
|
+
img.fetchPriority = fetchPriority;
|
|
148
|
+
}
|
|
149
|
+
const loadImage = () => {
|
|
150
|
+
if ("decode" in img && decoding === "async") {
|
|
151
|
+
img.decode().then(() => {
|
|
152
|
+
setImageSrc(src);
|
|
153
|
+
setImageDimensions({ width: img.naturalWidth, height: img.naturalHeight });
|
|
154
|
+
setIsLoading(false);
|
|
155
|
+
onLoad?.();
|
|
156
|
+
}).catch(() => {
|
|
157
|
+
setImageSrc(src);
|
|
158
|
+
setImageDimensions({ width: img.naturalWidth, height: img.naturalHeight });
|
|
159
|
+
setIsLoading(false);
|
|
160
|
+
onLoad?.();
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
img.onload = () => {
|
|
164
|
+
setImageSrc(src);
|
|
165
|
+
setImageDimensions({ width: img.naturalWidth, height: img.naturalHeight });
|
|
166
|
+
setIsLoading(false);
|
|
167
|
+
onLoad?.();
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
img.onerror = () => {
|
|
172
|
+
setIsLoading(false);
|
|
173
|
+
if (onError) {
|
|
174
|
+
onError();
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
setHasError(true);
|
|
178
|
+
};
|
|
179
|
+
img.src = src;
|
|
180
|
+
loadImage();
|
|
181
|
+
}
|
|
182
|
+
}, [src, shouldUseLazy, shouldLoad, imageSrc, onLoad, onError, decoding, fetchPriority]);
|
|
183
|
+
const getAspectRatioClass = () => {
|
|
184
|
+
switch (aspectRatio) {
|
|
185
|
+
case "auto": {
|
|
186
|
+
if (isLoading && !imageDimensions) {
|
|
187
|
+
return "aspect-[4/3]";
|
|
188
|
+
}
|
|
189
|
+
return "";
|
|
190
|
+
}
|
|
191
|
+
case "1/1": {
|
|
192
|
+
return "aspect-square";
|
|
193
|
+
}
|
|
194
|
+
case "4/3": {
|
|
195
|
+
return "aspect-[4/3]";
|
|
196
|
+
}
|
|
197
|
+
case "3/4": {
|
|
198
|
+
return "aspect-[3/4]";
|
|
199
|
+
}
|
|
200
|
+
case "16/9": {
|
|
201
|
+
return "aspect-video";
|
|
202
|
+
}
|
|
203
|
+
case "9/16": {
|
|
204
|
+
return "aspect-[9/16]";
|
|
205
|
+
}
|
|
206
|
+
case "2/3": {
|
|
207
|
+
return "aspect-[2/3]";
|
|
208
|
+
}
|
|
209
|
+
case "3/2": {
|
|
210
|
+
return "aspect-[3/2]";
|
|
211
|
+
}
|
|
212
|
+
case "5/4": {
|
|
213
|
+
return "aspect-[5/4]";
|
|
214
|
+
}
|
|
215
|
+
case "21/9": {
|
|
216
|
+
return "aspect-[21/9]";
|
|
217
|
+
}
|
|
218
|
+
case "9/21": {
|
|
219
|
+
return "aspect-[9/21]";
|
|
220
|
+
}
|
|
221
|
+
default: {
|
|
222
|
+
return "aspect-video";
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
if (!src) {
|
|
227
|
+
return /* @__PURE__ */ jsx(
|
|
228
|
+
"div",
|
|
229
|
+
{
|
|
230
|
+
className: cn(
|
|
231
|
+
"bg-muted flex items-center justify-center p-8",
|
|
232
|
+
getAspectRatioClass(),
|
|
233
|
+
containerClassName,
|
|
234
|
+
className
|
|
235
|
+
),
|
|
236
|
+
...props,
|
|
237
|
+
children: /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm", children: fallbackText })
|
|
238
|
+
}
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
if (hasError) {
|
|
242
|
+
return /* @__PURE__ */ jsx(
|
|
243
|
+
"div",
|
|
244
|
+
{
|
|
245
|
+
className: cn(
|
|
246
|
+
"bg-muted flex items-center justify-center p-8",
|
|
247
|
+
getAspectRatioClass(),
|
|
248
|
+
containerClassName,
|
|
249
|
+
className
|
|
250
|
+
),
|
|
251
|
+
...props,
|
|
252
|
+
children: /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm", children: errorText })
|
|
253
|
+
}
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
const aspectRatioStyle = aspectRatio === "auto" && imageDimensions ? { aspectRatio: `${imageDimensions.width} / ${imageDimensions.height}` } : void 0;
|
|
257
|
+
return /* @__PURE__ */ jsxs(
|
|
258
|
+
"div",
|
|
259
|
+
{
|
|
260
|
+
className: cn("relative", getAspectRatioClass(), className, containerClassName),
|
|
261
|
+
ref: shouldUseLazy ? lazyRef : void 0,
|
|
262
|
+
style: aspectRatioStyle,
|
|
263
|
+
...props,
|
|
264
|
+
children: [
|
|
265
|
+
isLoading && showSkeleton && /* @__PURE__ */ jsx(Skeleton, { className: cn("absolute inset-0 h-full w-full", skeletonClassName) }),
|
|
266
|
+
imageSrc && /* @__PURE__ */ jsx(
|
|
267
|
+
ImageDisplay,
|
|
268
|
+
{
|
|
269
|
+
alt,
|
|
270
|
+
aspectRatio,
|
|
271
|
+
imageClassName,
|
|
272
|
+
imageDimensions,
|
|
273
|
+
imageSrc,
|
|
274
|
+
isMobile,
|
|
275
|
+
reducedMotion
|
|
276
|
+
}
|
|
277
|
+
)
|
|
278
|
+
]
|
|
279
|
+
}
|
|
280
|
+
);
|
|
281
|
+
};
|
|
282
|
+
var ImageDisplayComponent = ({
|
|
283
|
+
imageSrc,
|
|
284
|
+
alt,
|
|
285
|
+
imageClassName,
|
|
286
|
+
aspectRatio,
|
|
287
|
+
imageDimensions,
|
|
288
|
+
isMobile,
|
|
289
|
+
reducedMotion
|
|
290
|
+
}) => {
|
|
291
|
+
const hasAnimatedBefore = animatedImagesCache.has(imageSrc);
|
|
292
|
+
const animationTimerRef = useRef(null);
|
|
293
|
+
useEffect(() => {
|
|
294
|
+
if (!hasAnimatedBefore) {
|
|
295
|
+
animationTimerRef.current = setTimeout(() => {
|
|
296
|
+
animatedImagesCache.add(imageSrc);
|
|
297
|
+
}, 500);
|
|
298
|
+
}
|
|
299
|
+
return () => {
|
|
300
|
+
if (animationTimerRef.current) {
|
|
301
|
+
clearTimeout(animationTimerRef.current);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}, [imageSrc, hasAnimatedBefore]);
|
|
305
|
+
const skipAnimation = hasAnimatedBefore || reducedMotion || isMobile;
|
|
306
|
+
if (aspectRatio === "auto") {
|
|
307
|
+
return skipAnimation ? /* @__PURE__ */ jsx(
|
|
308
|
+
"img",
|
|
309
|
+
{
|
|
310
|
+
alt: alt || "Image",
|
|
311
|
+
className: cn("h-auto w-full object-cover", imageClassName),
|
|
312
|
+
decoding: "async",
|
|
313
|
+
height: imageDimensions?.height ?? 600,
|
|
314
|
+
src: imageSrc,
|
|
315
|
+
style: { pointerEvents: "none" },
|
|
316
|
+
width: imageDimensions?.width ?? 800
|
|
317
|
+
}
|
|
318
|
+
) : /* @__PURE__ */ jsx(
|
|
319
|
+
motion.img,
|
|
320
|
+
{
|
|
321
|
+
alt: alt || "Image",
|
|
322
|
+
animate: { opacity: 1, scale: 1 },
|
|
323
|
+
className: cn("h-auto w-full object-cover", imageClassName),
|
|
324
|
+
decoding: "async",
|
|
325
|
+
height: imageDimensions?.height ?? 600,
|
|
326
|
+
initial: IMAGE_REVEAL_INITIAL,
|
|
327
|
+
src: imageSrc,
|
|
328
|
+
style: { pointerEvents: "none" },
|
|
329
|
+
transition: IMAGE_REVEAL_TRANSITION,
|
|
330
|
+
width: imageDimensions?.width ?? 800
|
|
331
|
+
}
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
return /* @__PURE__ */ jsx("div", { "aria-label": alt || "Image", className: "absolute inset-0 overflow-hidden", role: "img", children: skipAnimation ? (
|
|
335
|
+
// Static for mobile/reduced motion/already animated - no animation conflicts
|
|
336
|
+
/* @__PURE__ */ jsx(
|
|
337
|
+
"div",
|
|
338
|
+
{
|
|
339
|
+
className: cn("absolute inset-0 bg-cover bg-center bg-no-repeat", imageClassName),
|
|
340
|
+
style: {
|
|
341
|
+
backgroundImage: `url("${imageSrc}")`,
|
|
342
|
+
pointerEvents: "none"
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
)
|
|
346
|
+
) : (
|
|
347
|
+
// Framer Motion for desktop - but only animate on initial load
|
|
348
|
+
/* @__PURE__ */ jsx(
|
|
349
|
+
motion.div,
|
|
350
|
+
{
|
|
351
|
+
animate: IMAGE_REVEAL_ANIMATE,
|
|
352
|
+
className: cn("absolute inset-0 bg-cover bg-center bg-no-repeat", imageClassName),
|
|
353
|
+
initial: IMAGE_REVEAL_INITIAL,
|
|
354
|
+
style: {
|
|
355
|
+
backgroundImage: `url("${imageSrc}")`,
|
|
356
|
+
pointerEvents: "none"
|
|
357
|
+
},
|
|
358
|
+
transition: IMAGE_REVEAL_TRANSITION
|
|
359
|
+
}
|
|
360
|
+
)
|
|
361
|
+
) });
|
|
362
|
+
};
|
|
363
|
+
var ImageDisplay = memo(ImageDisplayComponent, (prevProps, nextProps) => {
|
|
364
|
+
return prevProps.imageSrc === nextProps.imageSrc && prevProps.aspectRatio === nextProps.aspectRatio && prevProps.isMobile === nextProps.isMobile && prevProps.reducedMotion === nextProps.reducedMotion;
|
|
365
|
+
});
|
|
366
|
+
var CHROME_IDLE_MS = 2500;
|
|
367
|
+
function useChromeAutoHide(open) {
|
|
368
|
+
const [visible, setVisible] = useState(true);
|
|
369
|
+
const idleTimerRef = useRef(null);
|
|
370
|
+
const holdsRef = useRef(/* @__PURE__ */ new Set());
|
|
371
|
+
const clearIdleTimer = useCallback(() => {
|
|
372
|
+
if (idleTimerRef.current !== null) {
|
|
373
|
+
clearTimeout(idleTimerRef.current);
|
|
374
|
+
idleTimerRef.current = null;
|
|
375
|
+
}
|
|
376
|
+
}, []);
|
|
377
|
+
const scheduleHide = useCallback(() => {
|
|
378
|
+
clearIdleTimer();
|
|
379
|
+
idleTimerRef.current = setTimeout(() => {
|
|
380
|
+
idleTimerRef.current = null;
|
|
381
|
+
if (holdsRef.current.size === 0) {
|
|
382
|
+
setVisible(false);
|
|
383
|
+
}
|
|
384
|
+
}, CHROME_IDLE_MS);
|
|
385
|
+
}, [clearIdleTimer]);
|
|
386
|
+
const reveal = useCallback(() => {
|
|
387
|
+
setVisible(true);
|
|
388
|
+
scheduleHide();
|
|
389
|
+
}, [scheduleHide]);
|
|
390
|
+
const hold = useCallback(
|
|
391
|
+
(reason) => {
|
|
392
|
+
holdsRef.current.add(reason);
|
|
393
|
+
clearIdleTimer();
|
|
394
|
+
setVisible(true);
|
|
395
|
+
},
|
|
396
|
+
[clearIdleTimer]
|
|
397
|
+
);
|
|
398
|
+
const release = useCallback(
|
|
399
|
+
(reason) => {
|
|
400
|
+
holdsRef.current.delete(reason);
|
|
401
|
+
if (holdsRef.current.size === 0) {
|
|
402
|
+
scheduleHide();
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
[scheduleHide]
|
|
406
|
+
);
|
|
407
|
+
useEffect(() => {
|
|
408
|
+
if (!open) {
|
|
409
|
+
clearIdleTimer();
|
|
410
|
+
holdsRef.current.clear();
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
setVisible(true);
|
|
414
|
+
scheduleHide();
|
|
415
|
+
return clearIdleTimer;
|
|
416
|
+
}, [open, clearIdleTimer, scheduleHide]);
|
|
417
|
+
useEffect(() => {
|
|
418
|
+
if (!open) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const handlePointerEnd = () => {
|
|
422
|
+
release("drag");
|
|
423
|
+
};
|
|
424
|
+
document.addEventListener("pointerup", handlePointerEnd);
|
|
425
|
+
document.addEventListener("pointercancel", handlePointerEnd);
|
|
426
|
+
return () => {
|
|
427
|
+
document.removeEventListener("pointerup", handlePointerEnd);
|
|
428
|
+
document.removeEventListener("pointercancel", handlePointerEnd);
|
|
429
|
+
};
|
|
430
|
+
}, [open, release]);
|
|
431
|
+
return {
|
|
432
|
+
holdDrag: useCallback(() => {
|
|
433
|
+
hold("drag");
|
|
434
|
+
}, [hold]),
|
|
435
|
+
holdFocus: useCallback(() => {
|
|
436
|
+
hold("focus");
|
|
437
|
+
}, [hold]),
|
|
438
|
+
holdHover: useCallback(() => {
|
|
439
|
+
hold("hover");
|
|
440
|
+
}, [hold]),
|
|
441
|
+
releaseDrag: useCallback(() => {
|
|
442
|
+
release("drag");
|
|
443
|
+
}, [release]),
|
|
444
|
+
releaseFocus: useCallback(() => {
|
|
445
|
+
release("focus");
|
|
446
|
+
}, [release]),
|
|
447
|
+
releaseHover: useCallback(() => {
|
|
448
|
+
release("hover");
|
|
449
|
+
}, [release]),
|
|
450
|
+
reveal,
|
|
451
|
+
visible
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
var SM_BREAKPOINT_PX = 640;
|
|
455
|
+
function useMinWidth(minWidthPx) {
|
|
456
|
+
const [aboveMinWidth, setAboveMinWidth] = useState(
|
|
457
|
+
() => typeof window === "undefined" ? true : window.innerWidth >= minWidthPx
|
|
458
|
+
);
|
|
459
|
+
useEffect(() => {
|
|
460
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
const mediaQuery = window.matchMedia(`(min-width: ${minWidthPx}px)`);
|
|
464
|
+
const handleChange = () => {
|
|
465
|
+
setAboveMinWidth(window.innerWidth >= minWidthPx);
|
|
466
|
+
};
|
|
467
|
+
handleChange();
|
|
468
|
+
mediaQuery.addEventListener("change", handleChange);
|
|
469
|
+
return () => {
|
|
470
|
+
mediaQuery.removeEventListener("change", handleChange);
|
|
471
|
+
};
|
|
472
|
+
}, [minWidthPx]);
|
|
473
|
+
return aboveMinWidth;
|
|
474
|
+
}
|
|
475
|
+
function isInternalFocusMove(event, rootRef) {
|
|
476
|
+
const related = event.relatedTarget;
|
|
477
|
+
return related instanceof Node && Boolean(rootRef.current?.contains(related));
|
|
478
|
+
}
|
|
479
|
+
function chromeOpacityClassName() {
|
|
480
|
+
return cn(
|
|
481
|
+
"opacity-[calc((1-var(--a63-media-lightbox-chrome-hidden,0))*(1-var(--a63-media-lightbox-pull,0)))]",
|
|
482
|
+
"transition-opacity duration-[var(--a63-control-feedback-duration,200ms)] motion-reduce:transition-none"
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
function chromeOpacityStyle(chrome) {
|
|
486
|
+
return { "--a63-media-lightbox-chrome-hidden": chrome.visible ? "0" : "1" };
|
|
487
|
+
}
|
|
488
|
+
function lightboxIconButtonClassName(tone = "glass") {
|
|
489
|
+
return cn(
|
|
490
|
+
"flex size-11 items-center justify-center outline-none",
|
|
491
|
+
"transition-colors duration-[var(--a63-control-feedback-duration,200ms)]",
|
|
492
|
+
"disabled:pointer-events-none disabled:opacity-30",
|
|
493
|
+
// The capsule's own surface is drawn by its wrapper, so its buttons carry
|
|
494
|
+
// no border, no background and no radius of their own — two glass pills
|
|
495
|
+
// inside a third would read as a seam rather than one control.
|
|
496
|
+
tone !== "capsule" && "rounded-full",
|
|
497
|
+
tone === "glass" && cn(
|
|
498
|
+
"a63-media-lightbox-on-media",
|
|
499
|
+
"focus-visible:ring-2 focus-visible:ring-[var(--a63-lightbox-on-media-ring)]"
|
|
500
|
+
),
|
|
501
|
+
tone === "capsule" && cn(
|
|
502
|
+
"text-[var(--a63-lightbox-on-media-fg)]",
|
|
503
|
+
"hover:bg-[var(--a63-lightbox-on-media-surface-hover)]",
|
|
504
|
+
"focus-visible:ring-2 focus-visible:ring-inset",
|
|
505
|
+
"focus-visible:ring-[var(--a63-lightbox-on-media-ring)]"
|
|
506
|
+
),
|
|
507
|
+
tone === "ghost" && cn(
|
|
508
|
+
"rounded-full text-[var(--a63-text-primary)] hover:bg-[var(--a63-surface-control-hover)]",
|
|
509
|
+
"focus-visible:ring-2 focus-visible:ring-[var(--a63-focus-ring)]"
|
|
510
|
+
)
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
function PresetFloatingChrome({ chrome }) {
|
|
514
|
+
const { transition } = useLightboxConfig();
|
|
515
|
+
const { rootRef } = useLightboxRefs();
|
|
516
|
+
const viewTransition = transition === "view-transition";
|
|
517
|
+
const pointerEventsClassName = chrome.visible ? "pointer-events-auto" : "pointer-events-none";
|
|
518
|
+
return /* @__PURE__ */ jsx(
|
|
519
|
+
"div",
|
|
520
|
+
{
|
|
521
|
+
className: cn("pointer-events-none absolute inset-0 z-20", chromeOpacityClassName()),
|
|
522
|
+
style: chromeOpacityStyle(chrome),
|
|
523
|
+
children: /* @__PURE__ */ jsxs(
|
|
524
|
+
motion.div,
|
|
525
|
+
{
|
|
526
|
+
animate: viewTransition ? void 0 : { opacity: 1 },
|
|
527
|
+
className: cn(
|
|
528
|
+
"pointer-events-none absolute inset-0",
|
|
529
|
+
"pt-[env(safe-area-inset-top)] pr-[env(safe-area-inset-right)]",
|
|
530
|
+
"pl-[env(safe-area-inset-left)]"
|
|
531
|
+
),
|
|
532
|
+
exit: viewTransition ? void 0 : { opacity: 0, transition: CHROME_OUT },
|
|
533
|
+
initial: viewTransition ? void 0 : { opacity: 0 },
|
|
534
|
+
onBlur: chrome.releaseFocus,
|
|
535
|
+
onFocus: (event) => {
|
|
536
|
+
if (isInternalFocusMove(event, rootRef)) {
|
|
537
|
+
chrome.holdFocus();
|
|
538
|
+
}
|
|
539
|
+
},
|
|
540
|
+
transition: CHROME_IN,
|
|
541
|
+
children: [
|
|
542
|
+
/* @__PURE__ */ jsxs(
|
|
543
|
+
"div",
|
|
544
|
+
{
|
|
545
|
+
className: cn("absolute top-4 right-4 flex items-center gap-1.5", pointerEventsClassName),
|
|
546
|
+
children: [
|
|
547
|
+
/* @__PURE__ */ jsx(Lightbox.AppearanceToggle, { className: lightboxIconButtonClassName("glass") }),
|
|
548
|
+
/* @__PURE__ */ jsx(Lightbox.Destination, { className: lightboxIconButtonClassName("glass") }),
|
|
549
|
+
/* @__PURE__ */ jsxs(
|
|
550
|
+
"div",
|
|
551
|
+
{
|
|
552
|
+
className: cn(
|
|
553
|
+
"a63-media-lightbox-on-media flex items-center overflow-hidden",
|
|
554
|
+
"rounded-full"
|
|
555
|
+
),
|
|
556
|
+
children: [
|
|
557
|
+
/* @__PURE__ */ jsx(Lightbox.ZoomOut, { className: lightboxIconButtonClassName("capsule"), children: /* @__PURE__ */ jsx(ZoomOut, { "aria-hidden": true, className: "size-5" }) }),
|
|
558
|
+
/* @__PURE__ */ jsx(
|
|
559
|
+
"span",
|
|
560
|
+
{
|
|
561
|
+
"aria-hidden": true,
|
|
562
|
+
className: "h-5 w-px shrink-0 bg-[var(--a63-lightbox-on-media-border)]"
|
|
563
|
+
}
|
|
564
|
+
),
|
|
565
|
+
/* @__PURE__ */ jsx(Lightbox.ZoomIn, { className: lightboxIconButtonClassName("capsule"), children: /* @__PURE__ */ jsx(ZoomIn, { "aria-hidden": true, className: "size-5" }) })
|
|
566
|
+
]
|
|
567
|
+
}
|
|
568
|
+
),
|
|
569
|
+
/* @__PURE__ */ jsx(Lightbox.Close, { className: lightboxIconButtonClassName("glass"), children: /* @__PURE__ */ jsx(X, { "aria-hidden": true, className: "size-5" }) })
|
|
570
|
+
]
|
|
571
|
+
}
|
|
572
|
+
),
|
|
573
|
+
/* @__PURE__ */ jsx(
|
|
574
|
+
"div",
|
|
575
|
+
{
|
|
576
|
+
className: cn(
|
|
577
|
+
"absolute top-1/2 left-4 hidden -translate-y-1/2 md:block",
|
|
578
|
+
pointerEventsClassName
|
|
579
|
+
),
|
|
580
|
+
children: /* @__PURE__ */ jsx(Lightbox.Previous, { className: lightboxIconButtonClassName("glass"), children: /* @__PURE__ */ jsx(ChevronLeft, { "aria-hidden": true, className: "size-5" }) })
|
|
581
|
+
}
|
|
582
|
+
),
|
|
583
|
+
/* @__PURE__ */ jsx(
|
|
584
|
+
"div",
|
|
585
|
+
{
|
|
586
|
+
className: cn(
|
|
587
|
+
"absolute top-1/2 right-4 hidden -translate-y-1/2 md:block",
|
|
588
|
+
pointerEventsClassName
|
|
589
|
+
),
|
|
590
|
+
children: /* @__PURE__ */ jsx(Lightbox.Next, { className: lightboxIconButtonClassName("glass"), children: /* @__PURE__ */ jsx(ChevronRight, { "aria-hidden": true, className: "size-5" }) })
|
|
591
|
+
}
|
|
592
|
+
)
|
|
593
|
+
]
|
|
594
|
+
}
|
|
595
|
+
)
|
|
596
|
+
}
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
function Dock({
|
|
600
|
+
chrome,
|
|
601
|
+
thumbnails
|
|
602
|
+
}) {
|
|
603
|
+
const { items, reducedMotion, transition } = useLightboxConfig();
|
|
604
|
+
const { index, itemCount } = useLightboxState();
|
|
605
|
+
const { rootRef } = useLightboxRefs();
|
|
606
|
+
const item = items[index];
|
|
607
|
+
const viewTransition = transition === "view-transition";
|
|
608
|
+
const isAboveSm = useMinWidth(SM_BREAKPOINT_PX);
|
|
609
|
+
const showThumbnails = thumbnails && itemCount > 1 && isAboveSm;
|
|
610
|
+
const pointerEventsClassName = chrome.visible ? "pointer-events-auto" : "pointer-events-none";
|
|
611
|
+
return /* @__PURE__ */ jsx(
|
|
612
|
+
"div",
|
|
613
|
+
{
|
|
614
|
+
className: cn(
|
|
615
|
+
"absolute inset-x-0 bottom-0 z-20",
|
|
616
|
+
chromeOpacityClassName(),
|
|
617
|
+
pointerEventsClassName
|
|
618
|
+
),
|
|
619
|
+
onBlur: chrome.releaseFocus,
|
|
620
|
+
onFocus: (event) => {
|
|
621
|
+
if (isInternalFocusMove(event, rootRef)) {
|
|
622
|
+
chrome.holdFocus();
|
|
623
|
+
}
|
|
624
|
+
},
|
|
625
|
+
onPointerDown: chrome.holdDrag,
|
|
626
|
+
onPointerEnter: chrome.holdHover,
|
|
627
|
+
onPointerLeave: chrome.releaseHover,
|
|
628
|
+
style: chromeOpacityStyle(chrome),
|
|
629
|
+
children: /* @__PURE__ */ jsx(
|
|
630
|
+
motion.div,
|
|
631
|
+
{
|
|
632
|
+
animate: viewTransition ? void 0 : { opacity: 1, y: 0 },
|
|
633
|
+
exit: viewTransition ? void 0 : {
|
|
634
|
+
opacity: 0,
|
|
635
|
+
transition: CHROME_OUT,
|
|
636
|
+
y: reducedMotion ? 0 : CHROME_EXIT_OFFSET
|
|
637
|
+
},
|
|
638
|
+
initial: viewTransition ? void 0 : { opacity: 0, y: reducedMotion ? 0 : CHROME_EXIT_OFFSET },
|
|
639
|
+
transition: CHROME_IN,
|
|
640
|
+
children: /* @__PURE__ */ jsx(
|
|
641
|
+
"div",
|
|
642
|
+
{
|
|
643
|
+
className: cn(
|
|
644
|
+
"flex w-full flex-col items-center gap-2.5",
|
|
645
|
+
"px-3 pt-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]",
|
|
646
|
+
"text-[var(--a63-text-primary)]"
|
|
647
|
+
),
|
|
648
|
+
"data-slot": "media-lightbox-dock",
|
|
649
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[min(92vw,1400px)] flex-col items-center gap-2.5", children: [
|
|
650
|
+
/* @__PURE__ */ jsxs("div", { className: "flex max-w-full items-baseline justify-center gap-3", children: [
|
|
651
|
+
item?.caption ? /* @__PURE__ */ jsx(Lightbox.Caption, { className: "min-w-0 truncate text-center text-sm text-[var(--a63-text-secondary)]" }) : null,
|
|
652
|
+
itemCount > 1 && !showThumbnails ? /* @__PURE__ */ jsx(
|
|
653
|
+
Lightbox.Counter,
|
|
654
|
+
{
|
|
655
|
+
"aria-hidden": true,
|
|
656
|
+
className: cn(
|
|
657
|
+
"shrink-0 font-mono text-xs text-[var(--a63-text-secondary)]",
|
|
658
|
+
"tabular-nums opacity-70"
|
|
659
|
+
)
|
|
660
|
+
}
|
|
661
|
+
) : null
|
|
662
|
+
] }),
|
|
663
|
+
showThumbnails ? /* @__PURE__ */ jsx(Lightbox.Thumbnails, { className: "max-w-full min-w-0 justify-start sm:justify-center", children: (thumbnail) => /* @__PURE__ */ jsx(
|
|
664
|
+
Lightbox.Thumbnail,
|
|
665
|
+
{
|
|
666
|
+
className: cn(
|
|
667
|
+
"relative h-11 w-14 shrink-0 snap-center overflow-hidden rounded-md outline-none",
|
|
668
|
+
"bg-[var(--a63-lightbox-on-media-surface)]",
|
|
669
|
+
"focus-visible:ring-2 focus-visible:ring-[var(--a63-lightbox-on-media-ring)]",
|
|
670
|
+
// Opacity alone. The thumbs used to scale between
|
|
671
|
+
// states as well, which put a size change next to the
|
|
672
|
+
// photo's own dissolve and read as the picture being
|
|
673
|
+
// zoomed rather than crossfaded.
|
|
674
|
+
"transition-opacity duration-[var(--a63-control-feedback-duration,200ms)]",
|
|
675
|
+
"ease-[var(--a63-motion-ease-emphasized,ease-out)] motion-reduce:transition-none",
|
|
676
|
+
thumbnail.isActive ? "opacity-100 ring-2 ring-[var(--a63-lightbox-on-media-fg)]" : "opacity-50 hover:opacity-80"
|
|
677
|
+
)
|
|
678
|
+
},
|
|
679
|
+
thumbnail.item.id
|
|
680
|
+
) }) : null
|
|
681
|
+
] })
|
|
682
|
+
}
|
|
683
|
+
)
|
|
684
|
+
}
|
|
685
|
+
)
|
|
686
|
+
}
|
|
687
|
+
);
|
|
688
|
+
}
|
|
689
|
+
function SlideCloseArea() {
|
|
690
|
+
const { labels } = useLightboxConfig();
|
|
691
|
+
const { close } = useLightboxState();
|
|
692
|
+
return /* @__PURE__ */ jsx(
|
|
693
|
+
"button",
|
|
694
|
+
{
|
|
695
|
+
"aria-hidden": true,
|
|
696
|
+
"aria-label": labels.close,
|
|
697
|
+
className: "absolute inset-0 cursor-default outline-none",
|
|
698
|
+
onClick: close,
|
|
699
|
+
tabIndex: -1,
|
|
700
|
+
type: "button"
|
|
701
|
+
}
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
function MediaLightbox({
|
|
705
|
+
appearance,
|
|
706
|
+
className,
|
|
707
|
+
index,
|
|
708
|
+
items,
|
|
709
|
+
labels,
|
|
710
|
+
onAppearanceChange,
|
|
711
|
+
onExitComplete,
|
|
712
|
+
onIndexChange,
|
|
713
|
+
onOpenChange,
|
|
714
|
+
open,
|
|
715
|
+
origin,
|
|
716
|
+
preload,
|
|
717
|
+
thumbnails,
|
|
718
|
+
transition = "flip"
|
|
719
|
+
}) {
|
|
720
|
+
const chrome = useChromeAutoHide(open);
|
|
721
|
+
return /* @__PURE__ */ jsx(
|
|
722
|
+
Lightbox.Root,
|
|
723
|
+
{
|
|
724
|
+
appearance,
|
|
725
|
+
index,
|
|
726
|
+
items,
|
|
727
|
+
labels,
|
|
728
|
+
onAppearanceChange,
|
|
729
|
+
onIndexChange,
|
|
730
|
+
onOpenChange,
|
|
731
|
+
open,
|
|
732
|
+
origin,
|
|
733
|
+
preload,
|
|
734
|
+
transition,
|
|
735
|
+
children: /* @__PURE__ */ jsxs(Lightbox.Portal, { onExitComplete, children: [
|
|
736
|
+
/* @__PURE__ */ jsx(Lightbox.Backdrop, { className: "bg-[var(--a63-surface-page)]" }),
|
|
737
|
+
/* @__PURE__ */ jsxs(
|
|
738
|
+
Lightbox.Content,
|
|
739
|
+
{
|
|
740
|
+
className,
|
|
741
|
+
onKeyDownCapture: chrome.reveal,
|
|
742
|
+
onPointerMove: chrome.reveal,
|
|
743
|
+
children: [
|
|
744
|
+
/* @__PURE__ */ jsx(Lightbox.Status, {}),
|
|
745
|
+
/* @__PURE__ */ jsxs(Lightbox.Viewport, { className: "relative z-10 min-h-0 flex-1", onPointerDown: chrome.reveal, children: [
|
|
746
|
+
/* @__PURE__ */ jsx(Lightbox.Slides, { children: (slide) => /* @__PURE__ */ jsxs(Lightbox.Slide, { children: [
|
|
747
|
+
/* @__PURE__ */ jsx(SlideCloseArea, {}),
|
|
748
|
+
/* @__PURE__ */ jsx(Lightbox.Frame, { className: "rounded-2xl", children: /* @__PURE__ */ jsx(Lightbox.Zoom, { children: /* @__PURE__ */ jsx(Lightbox.Media, {}) }) })
|
|
749
|
+
] }, slide.item.id) }),
|
|
750
|
+
/* @__PURE__ */ jsx(PresetFloatingChrome, { chrome })
|
|
751
|
+
] }),
|
|
752
|
+
/* @__PURE__ */ jsx(Dock, { chrome, thumbnails: Boolean(thumbnails) })
|
|
753
|
+
]
|
|
754
|
+
}
|
|
755
|
+
)
|
|
756
|
+
] })
|
|
757
|
+
}
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
var KEEP_OUT_PX = 20;
|
|
761
|
+
var NO_EXCLUDE_REFS = [];
|
|
762
|
+
function isInsideKeepOut(clientX, clientY, excludeRefs) {
|
|
763
|
+
for (const ref of excludeRefs) {
|
|
764
|
+
const element = ref.current;
|
|
765
|
+
if (!element) {
|
|
766
|
+
continue;
|
|
767
|
+
}
|
|
768
|
+
const rect = element.getBoundingClientRect();
|
|
769
|
+
if (clientX >= rect.left - KEEP_OUT_PX && clientX <= rect.right + KEEP_OUT_PX && clientY >= rect.top - KEEP_OUT_PX && clientY <= rect.bottom + KEEP_OUT_PX) {
|
|
770
|
+
return true;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
return false;
|
|
774
|
+
}
|
|
775
|
+
function useMediaLightboxZoomCursor({
|
|
776
|
+
excludeRefs = NO_EXCLUDE_REFS
|
|
777
|
+
} = {}) {
|
|
778
|
+
const [active, setActive] = useState(false);
|
|
779
|
+
const [overlay, setOverlay] = useState({ x: 0, y: 0 });
|
|
780
|
+
const excludeRefsRef = useRef(excludeRefs);
|
|
781
|
+
excludeRefsRef.current = excludeRefs;
|
|
782
|
+
const suppressedRef = useRef(false);
|
|
783
|
+
const onPointerMove = useCallback((event) => {
|
|
784
|
+
if (event.pointerType === "touch" || suppressedRef.current) {
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
if (isInsideKeepOut(event.clientX, event.clientY, excludeRefsRef.current)) {
|
|
788
|
+
setActive(false);
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
792
|
+
setOverlay({ x: event.clientX - rect.left, y: event.clientY - rect.top });
|
|
793
|
+
setActive(true);
|
|
794
|
+
}, []);
|
|
795
|
+
const onPointerDown = useCallback(() => {
|
|
796
|
+
suppressedRef.current = true;
|
|
797
|
+
setActive(false);
|
|
798
|
+
}, []);
|
|
799
|
+
const onPointerLeave = useCallback(() => {
|
|
800
|
+
suppressedRef.current = false;
|
|
801
|
+
setActive(false);
|
|
802
|
+
}, []);
|
|
803
|
+
return {
|
|
804
|
+
active,
|
|
805
|
+
overlay,
|
|
806
|
+
targetProps: {
|
|
807
|
+
"data-zoom-cursor-active": active ? "" : void 0,
|
|
808
|
+
onPointerDown,
|
|
809
|
+
onPointerLeave,
|
|
810
|
+
onPointerMove
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
function MediaLightboxZoomCursor({
|
|
815
|
+
active,
|
|
816
|
+
x,
|
|
817
|
+
y
|
|
818
|
+
}) {
|
|
819
|
+
const reducedMotion = useReducedMotion();
|
|
820
|
+
return /* @__PURE__ */ jsx(AnimatePresence, { children: active ? /* @__PURE__ */ jsx(
|
|
821
|
+
motion.div,
|
|
822
|
+
{
|
|
823
|
+
animate: { opacity: 1, scale: 1 },
|
|
824
|
+
className: "a63-media-lightbox-zoom-cursor",
|
|
825
|
+
"data-slot": "media-lightbox-zoom-cursor",
|
|
826
|
+
exit: reducedMotion ? { opacity: 0 } : { opacity: 0, scale: 0 },
|
|
827
|
+
initial: reducedMotion ? { opacity: 0 } : { opacity: 0, scale: 0 },
|
|
828
|
+
style: { left: x, top: y },
|
|
829
|
+
transition: reducedMotion ? { duration: 0 } : { duration: 0.12, ease: "easeOut" },
|
|
830
|
+
children: /* @__PURE__ */ jsx(Plus, { "aria-hidden": true, className: "size-5" })
|
|
831
|
+
}
|
|
832
|
+
) : null });
|
|
833
|
+
}
|
|
834
|
+
function clamp(value, itemCount) {
|
|
835
|
+
if (itemCount <= 0) {
|
|
836
|
+
return 0;
|
|
837
|
+
}
|
|
838
|
+
return Math.min(Math.max(value, 0), itemCount - 1);
|
|
839
|
+
}
|
|
840
|
+
function useMediaLightbox(itemCount, options) {
|
|
841
|
+
const morph = options?.morph ?? "flip";
|
|
842
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
843
|
+
const [index, setIndexState] = useState(0);
|
|
844
|
+
const [origin, setOrigin] = useState(null);
|
|
845
|
+
const [transition, setTransition] = useState("flip");
|
|
846
|
+
const setIndex = useCallback(
|
|
847
|
+
(next) => {
|
|
848
|
+
setIndexState(clamp(next, itemCount));
|
|
849
|
+
},
|
|
850
|
+
[itemCount]
|
|
851
|
+
);
|
|
852
|
+
const openAt = useCallback(
|
|
853
|
+
(next, nextOrigin) => {
|
|
854
|
+
const target = nextOrigin ?? null;
|
|
855
|
+
const open = () => {
|
|
856
|
+
setOrigin(target);
|
|
857
|
+
setIndexState(clamp(next, itemCount));
|
|
858
|
+
setIsOpen(true);
|
|
859
|
+
};
|
|
860
|
+
const useViewTransition = morph === "view-transition" && supportsViewTransitions() && !preferCheapMediaTransition();
|
|
861
|
+
if (!useViewTransition) {
|
|
862
|
+
setTransition("flip");
|
|
863
|
+
open();
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
setTransition("view-transition");
|
|
867
|
+
const ran = runMediaViewTransition({ direction: "in", origin: target, update: open });
|
|
868
|
+
if (!ran) {
|
|
869
|
+
setTransition("flip");
|
|
870
|
+
open();
|
|
871
|
+
}
|
|
872
|
+
},
|
|
873
|
+
[itemCount, morph]
|
|
874
|
+
);
|
|
875
|
+
const close = useCallback(
|
|
876
|
+
(nextOrigin) => {
|
|
877
|
+
const target = nextOrigin === void 0 ? origin : nextOrigin;
|
|
878
|
+
const shut = () => {
|
|
879
|
+
setOrigin(target);
|
|
880
|
+
setIsOpen(false);
|
|
881
|
+
};
|
|
882
|
+
if (transition !== "view-transition") {
|
|
883
|
+
shut();
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
const ran = runMediaViewTransition({ direction: "out", origin: target, update: shut });
|
|
887
|
+
if (!ran) {
|
|
888
|
+
shut();
|
|
889
|
+
}
|
|
890
|
+
},
|
|
891
|
+
[origin, transition]
|
|
892
|
+
);
|
|
893
|
+
return useMemo(
|
|
894
|
+
() => ({ close, index, isOpen, openAt, origin, setIndex, transition }),
|
|
895
|
+
[close, index, isOpen, openAt, origin, setIndex, transition]
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
var VIDEO_FILE_REGEX = /\.(mp4|webm|ogg|mov|avi)$/i;
|
|
899
|
+
function detectVideoType(src) {
|
|
900
|
+
const extension = src.split(".").pop()?.toLowerCase();
|
|
901
|
+
switch (extension) {
|
|
902
|
+
case "webm":
|
|
903
|
+
return "video/webm";
|
|
904
|
+
case "ogg":
|
|
905
|
+
case "ogv":
|
|
906
|
+
return "video/ogg";
|
|
907
|
+
case "mov":
|
|
908
|
+
return "video/quicktime";
|
|
909
|
+
case "avi":
|
|
910
|
+
return "video/x-msvideo";
|
|
911
|
+
default:
|
|
912
|
+
return "video/mp4";
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
var Video = forwardRef(
|
|
916
|
+
({
|
|
917
|
+
className,
|
|
918
|
+
sources,
|
|
919
|
+
fallbackText = "Your browser does not support the video tag.",
|
|
920
|
+
asThumbnail = false,
|
|
921
|
+
...props
|
|
922
|
+
}, ref) => {
|
|
923
|
+
const isVideoFile = sources.length === 1 && VIDEO_FILE_REGEX.test(sources[0].src);
|
|
924
|
+
const useThumbnailMode = asThumbnail || isVideoFile;
|
|
925
|
+
const thumbnailProps = useThumbnailMode ? {
|
|
926
|
+
autoPlay: true,
|
|
927
|
+
muted: true,
|
|
928
|
+
loop: true,
|
|
929
|
+
controls: false,
|
|
930
|
+
playsInline: true
|
|
931
|
+
// Prevents fullscreen on mobile
|
|
932
|
+
} : {};
|
|
933
|
+
return /* @__PURE__ */ jsxs("video", { className: cn("h-auto w-full", className), ref, ...thumbnailProps, ...props, children: [
|
|
934
|
+
sources.map((source) => /* @__PURE__ */ jsx(
|
|
935
|
+
"source",
|
|
936
|
+
{
|
|
937
|
+
src: source.src,
|
|
938
|
+
type: source.type || detectVideoType(source.src)
|
|
939
|
+
},
|
|
940
|
+
source.src
|
|
941
|
+
)),
|
|
942
|
+
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground p-4 text-center", children: fallbackText })
|
|
943
|
+
] });
|
|
944
|
+
}
|
|
945
|
+
);
|
|
946
|
+
Video.displayName = "Video";
|
|
947
|
+
var VideoManagerContext = createContext(null);
|
|
948
|
+
function VideoManagerProvider({
|
|
949
|
+
children,
|
|
950
|
+
maxConcurrentVideos = 3
|
|
951
|
+
}) {
|
|
952
|
+
const videosRef = useRef(/* @__PURE__ */ new Map());
|
|
953
|
+
const iframesRef = useRef(/* @__PURE__ */ new Map());
|
|
954
|
+
const playingVideosRef = useRef(/* @__PURE__ */ new Set());
|
|
955
|
+
const playingIframesRef = useRef(/* @__PURE__ */ new Set());
|
|
956
|
+
const pausedByDialogRef = useRef(/* @__PURE__ */ new Set());
|
|
957
|
+
const pausedIframesByDialogRef = useRef(/* @__PURE__ */ new Set());
|
|
958
|
+
const value = useMemo(() => {
|
|
959
|
+
const evictOldestIfNeeded = () => {
|
|
960
|
+
if (playingVideosRef.current.size < maxConcurrentVideos) return;
|
|
961
|
+
const oldestId = playingVideosRef.current.values().next().value;
|
|
962
|
+
if (!oldestId) return;
|
|
963
|
+
const oldestVideo = videosRef.current.get(oldestId);
|
|
964
|
+
if (oldestVideo && !oldestVideo.paused) {
|
|
965
|
+
oldestVideo.pause();
|
|
966
|
+
}
|
|
967
|
+
playingVideosRef.current.delete(oldestId);
|
|
968
|
+
};
|
|
969
|
+
return {
|
|
970
|
+
registerVideo(id, videoElement) {
|
|
971
|
+
videosRef.current.set(id, videoElement);
|
|
972
|
+
if (!videoElement.paused) {
|
|
973
|
+
playingVideosRef.current.add(id);
|
|
974
|
+
}
|
|
975
|
+
},
|
|
976
|
+
unregisterVideo(id) {
|
|
977
|
+
videosRef.current.delete(id);
|
|
978
|
+
playingVideosRef.current.delete(id);
|
|
979
|
+
pausedByDialogRef.current.delete(id);
|
|
980
|
+
},
|
|
981
|
+
registerIframe(id, iframeElement) {
|
|
982
|
+
iframesRef.current.set(id, iframeElement);
|
|
983
|
+
playingIframesRef.current.add(id);
|
|
984
|
+
},
|
|
985
|
+
unregisterIframe(id) {
|
|
986
|
+
iframesRef.current.delete(id);
|
|
987
|
+
playingIframesRef.current.delete(id);
|
|
988
|
+
pausedIframesByDialogRef.current.delete(id);
|
|
989
|
+
},
|
|
990
|
+
playVideo(id) {
|
|
991
|
+
const video = videosRef.current.get(id);
|
|
992
|
+
if (!video) return;
|
|
993
|
+
evictOldestIfNeeded();
|
|
994
|
+
video.play().then(() => {
|
|
995
|
+
playingVideosRef.current.add(id);
|
|
996
|
+
}).catch(() => {
|
|
997
|
+
});
|
|
998
|
+
},
|
|
999
|
+
pauseVideo(id) {
|
|
1000
|
+
const video = videosRef.current.get(id);
|
|
1001
|
+
if (video && !video.paused) {
|
|
1002
|
+
video.pause();
|
|
1003
|
+
playingVideosRef.current.delete(id);
|
|
1004
|
+
}
|
|
1005
|
+
},
|
|
1006
|
+
pauseAllVideos() {
|
|
1007
|
+
pausedByDialogRef.current.clear();
|
|
1008
|
+
pausedIframesByDialogRef.current.clear();
|
|
1009
|
+
for (const [id, video] of videosRef.current.entries()) {
|
|
1010
|
+
const wasPlaying = !video.paused;
|
|
1011
|
+
video.pause();
|
|
1012
|
+
if (wasPlaying || video.autoplay) {
|
|
1013
|
+
pausedByDialogRef.current.add(id);
|
|
1014
|
+
}
|
|
1015
|
+
playingVideosRef.current.delete(id);
|
|
1016
|
+
}
|
|
1017
|
+
for (const [id, iframe] of iframesRef.current.entries()) {
|
|
1018
|
+
pausedIframesByDialogRef.current.add(id);
|
|
1019
|
+
try {
|
|
1020
|
+
iframe.contentWindow?.postMessage(JSON.stringify({ method: "pause" }), "*");
|
|
1021
|
+
iframe.contentWindow?.postMessage(
|
|
1022
|
+
JSON.stringify({ event: "command", func: "pauseVideo" }),
|
|
1023
|
+
"*"
|
|
1024
|
+
);
|
|
1025
|
+
} catch {
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
},
|
|
1029
|
+
resumeAllVideos() {
|
|
1030
|
+
const videosToResume = new Set(pausedByDialogRef.current);
|
|
1031
|
+
const iframesToResume = new Set(pausedIframesByDialogRef.current);
|
|
1032
|
+
pausedByDialogRef.current.clear();
|
|
1033
|
+
pausedIframesByDialogRef.current.clear();
|
|
1034
|
+
for (const [id, video] of videosRef.current.entries()) {
|
|
1035
|
+
if (videosToResume.has(id)) {
|
|
1036
|
+
video.play().then(() => {
|
|
1037
|
+
playingVideosRef.current.add(id);
|
|
1038
|
+
}).catch(() => {
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
for (const [id, iframe] of iframesRef.current.entries()) {
|
|
1043
|
+
if (iframesToResume.has(id)) {
|
|
1044
|
+
setTimeout(() => {
|
|
1045
|
+
iframe.contentWindow?.postMessage(JSON.stringify({ method: "play" }), "*");
|
|
1046
|
+
iframe.contentWindow?.postMessage(
|
|
1047
|
+
JSON.stringify({ event: "command", func: "playVideo" }),
|
|
1048
|
+
"*"
|
|
1049
|
+
);
|
|
1050
|
+
}, 100);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
};
|
|
1055
|
+
}, [maxConcurrentVideos]);
|
|
1056
|
+
return /* @__PURE__ */ jsx(VideoManagerContext.Provider, { value, children });
|
|
1057
|
+
}
|
|
1058
|
+
function useVideoManager() {
|
|
1059
|
+
const context = useContext(VideoManagerContext);
|
|
1060
|
+
if (!context) {
|
|
1061
|
+
throw new Error("useVideoManager must be used within a VideoManagerProvider");
|
|
1062
|
+
}
|
|
1063
|
+
return context;
|
|
1064
|
+
}
|
|
1065
|
+
function detectVideoType2(src) {
|
|
1066
|
+
const extension = src.split(".").pop()?.toLowerCase();
|
|
1067
|
+
switch (extension) {
|
|
1068
|
+
case "webm":
|
|
1069
|
+
return "video/webm";
|
|
1070
|
+
case "ogg":
|
|
1071
|
+
case "ogv":
|
|
1072
|
+
return "video/ogg";
|
|
1073
|
+
case "mov":
|
|
1074
|
+
return "video/quicktime";
|
|
1075
|
+
case "avi":
|
|
1076
|
+
return "video/x-msvideo";
|
|
1077
|
+
default:
|
|
1078
|
+
return "video/mp4";
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
var VideoDialog = ({
|
|
1082
|
+
isOpen,
|
|
1083
|
+
onOpenChange,
|
|
1084
|
+
videoSources = [],
|
|
1085
|
+
title = "Video Player",
|
|
1086
|
+
trigger,
|
|
1087
|
+
className,
|
|
1088
|
+
captionsSrc,
|
|
1089
|
+
vimeoId,
|
|
1090
|
+
isVimeo = false,
|
|
1091
|
+
youtubeId,
|
|
1092
|
+
isYouTube = false
|
|
1093
|
+
}) => {
|
|
1094
|
+
const modalVideoRef = useRef(null);
|
|
1095
|
+
const iframeRef = useRef(null);
|
|
1096
|
+
const previousOpenRef = useRef(false);
|
|
1097
|
+
const videoManager = useContext(VideoManagerContext);
|
|
1098
|
+
useEffect(() => {
|
|
1099
|
+
const wasOpen = previousOpenRef.current;
|
|
1100
|
+
previousOpenRef.current = isOpen;
|
|
1101
|
+
if (!wasOpen && isOpen) {
|
|
1102
|
+
videoManager?.pauseAllVideos();
|
|
1103
|
+
const frame = requestAnimationFrame(() => {
|
|
1104
|
+
void modalVideoRef.current?.play().catch(() => {
|
|
1105
|
+
});
|
|
1106
|
+
});
|
|
1107
|
+
return () => cancelAnimationFrame(frame);
|
|
1108
|
+
}
|
|
1109
|
+
if (wasOpen && !isOpen) {
|
|
1110
|
+
videoManager?.resumeAllVideos();
|
|
1111
|
+
}
|
|
1112
|
+
}, [isOpen, videoManager]);
|
|
1113
|
+
const renderVideoContent = () => {
|
|
1114
|
+
if (isVimeo && vimeoId) {
|
|
1115
|
+
return /* @__PURE__ */ jsx(
|
|
1116
|
+
"iframe",
|
|
1117
|
+
{
|
|
1118
|
+
allow: "autoplay; fullscreen; picture-in-picture",
|
|
1119
|
+
allowFullScreen: true,
|
|
1120
|
+
className: "aspect-video w-full",
|
|
1121
|
+
frameBorder: "0",
|
|
1122
|
+
ref: iframeRef,
|
|
1123
|
+
src: `https://player.vimeo.com/video/${vimeoId}?autoplay=1&loop=1&muted=1`,
|
|
1124
|
+
title
|
|
1125
|
+
}
|
|
1126
|
+
);
|
|
1127
|
+
}
|
|
1128
|
+
if (isYouTube && youtubeId) {
|
|
1129
|
+
return /* @__PURE__ */ jsx(
|
|
1130
|
+
"iframe",
|
|
1131
|
+
{
|
|
1132
|
+
allow: "autoplay; fullscreen; picture-in-picture; encrypted-media",
|
|
1133
|
+
allowFullScreen: true,
|
|
1134
|
+
className: "aspect-video w-full",
|
|
1135
|
+
frameBorder: "0",
|
|
1136
|
+
ref: iframeRef,
|
|
1137
|
+
src: `https://www.youtube.com/embed/${youtubeId}?autoplay=1&loop=1&mute=1&controls=1&playlist=${youtubeId}`,
|
|
1138
|
+
title
|
|
1139
|
+
}
|
|
1140
|
+
);
|
|
1141
|
+
}
|
|
1142
|
+
return /* @__PURE__ */ jsxs(
|
|
1143
|
+
"video",
|
|
1144
|
+
{
|
|
1145
|
+
autoPlay: true,
|
|
1146
|
+
className: "aspect-video w-full",
|
|
1147
|
+
controls: true,
|
|
1148
|
+
loop: true,
|
|
1149
|
+
muted: true,
|
|
1150
|
+
playsInline: true,
|
|
1151
|
+
ref: modalVideoRef,
|
|
1152
|
+
children: [
|
|
1153
|
+
videoSources.map((source) => /* @__PURE__ */ jsx(
|
|
1154
|
+
"source",
|
|
1155
|
+
{
|
|
1156
|
+
src: source.src,
|
|
1157
|
+
type: source.type || detectVideoType2(source.src)
|
|
1158
|
+
},
|
|
1159
|
+
`${source.src}-${source.type || detectVideoType2(source.src)}`
|
|
1160
|
+
)),
|
|
1161
|
+
/* @__PURE__ */ jsx(
|
|
1162
|
+
"track",
|
|
1163
|
+
{
|
|
1164
|
+
default: true,
|
|
1165
|
+
kind: "captions",
|
|
1166
|
+
label: "English",
|
|
1167
|
+
lang: "en",
|
|
1168
|
+
src: captionsSrc || "data:text/vtt;base64,V0VCVlRUCg=="
|
|
1169
|
+
}
|
|
1170
|
+
),
|
|
1171
|
+
"Your browser does not support the video tag."
|
|
1172
|
+
]
|
|
1173
|
+
}
|
|
1174
|
+
);
|
|
1175
|
+
};
|
|
1176
|
+
return /* @__PURE__ */ jsxs(Dialog.Root, { onOpenChange, open: isOpen, children: [
|
|
1177
|
+
/* @__PURE__ */ jsx(Dialog.Trigger, { render: trigger }),
|
|
1178
|
+
/* @__PURE__ */ jsxs(Dialog.Portal, { children: [
|
|
1179
|
+
/* @__PURE__ */ jsx(
|
|
1180
|
+
Dialog.Backdrop,
|
|
1181
|
+
{
|
|
1182
|
+
className: "fixed inset-0 z-(--z-layer-overlay) bg-black/70 backdrop-blur-sm transition-opacity duration-200 data-ending-style:opacity-0 data-starting-style:opacity-0",
|
|
1183
|
+
"data-media-overlay": "video"
|
|
1184
|
+
}
|
|
1185
|
+
),
|
|
1186
|
+
/* @__PURE__ */ jsx(
|
|
1187
|
+
Dialog.Viewport,
|
|
1188
|
+
{
|
|
1189
|
+
className: "fixed inset-0 z-(--z-layer-overlay) grid place-items-center p-4",
|
|
1190
|
+
"data-media-overlay": "video",
|
|
1191
|
+
children: /* @__PURE__ */ jsxs(
|
|
1192
|
+
Dialog.Popup,
|
|
1193
|
+
{
|
|
1194
|
+
className: cn(
|
|
1195
|
+
"relative w-full max-w-7xl origin-center overflow-hidden rounded-2xl bg-black transition-[opacity,scale] duration-200 outline-none data-ending-style:scale-95 data-ending-style:opacity-0 data-starting-style:scale-95 data-starting-style:opacity-0",
|
|
1196
|
+
className
|
|
1197
|
+
),
|
|
1198
|
+
"data-media-overlay": "video",
|
|
1199
|
+
children: [
|
|
1200
|
+
/* @__PURE__ */ jsx(Dialog.Title, { className: "sr-only", children: title }),
|
|
1201
|
+
/* @__PURE__ */ jsxs(Dialog.Description, { className: "sr-only", children: [
|
|
1202
|
+
"Video player dialog for ",
|
|
1203
|
+
title
|
|
1204
|
+
] }),
|
|
1205
|
+
isOpen ? renderVideoContent() : null
|
|
1206
|
+
]
|
|
1207
|
+
}
|
|
1208
|
+
)
|
|
1209
|
+
}
|
|
1210
|
+
)
|
|
1211
|
+
] })
|
|
1212
|
+
] });
|
|
1213
|
+
};
|
|
1214
|
+
var IconButton = ({
|
|
1215
|
+
icon,
|
|
1216
|
+
className,
|
|
1217
|
+
"aria-label": ariaLabel,
|
|
1218
|
+
...props
|
|
1219
|
+
}) => {
|
|
1220
|
+
return /* @__PURE__ */ jsx(
|
|
1221
|
+
"button",
|
|
1222
|
+
{
|
|
1223
|
+
"aria-label": ariaLabel,
|
|
1224
|
+
className: cn(
|
|
1225
|
+
"rounded-full bg-black/70 p-2 transition-transform duration-300 group-hover:scale-110",
|
|
1226
|
+
className
|
|
1227
|
+
),
|
|
1228
|
+
type: "button",
|
|
1229
|
+
...props,
|
|
1230
|
+
children: /* @__PURE__ */ jsx("div", { className: "rounded-full bg-gradient-to-b from-white/10 to-white/5 p-3 transition-transform duration-300 group-hover:scale-110", children: /* @__PURE__ */ jsxs("div", { className: "flex h-8 w-8 items-center justify-center text-white", children: [
|
|
1231
|
+
icon === "play" && /* @__PURE__ */ jsx(Play, { className: "ml-1 h-8 w-8" }),
|
|
1232
|
+
icon === "maximize" && /* @__PURE__ */ jsx(Maximize, { className: "h-8 w-8" })
|
|
1233
|
+
] }) })
|
|
1234
|
+
}
|
|
1235
|
+
);
|
|
1236
|
+
};
|
|
1237
|
+
var VideoModal = ({
|
|
1238
|
+
videoSources = [],
|
|
1239
|
+
title,
|
|
1240
|
+
className,
|
|
1241
|
+
mode = "autoplay",
|
|
1242
|
+
aspectRatio = "aspect-[21/9]",
|
|
1243
|
+
alt,
|
|
1244
|
+
vimeoId,
|
|
1245
|
+
isVimeo = false,
|
|
1246
|
+
vimeoThumbnail
|
|
1247
|
+
}) => {
|
|
1248
|
+
const videoRef = useRef(null);
|
|
1249
|
+
const previewIframeRef = useRef(null);
|
|
1250
|
+
const [isPlaying, setIsPlaying] = useState(mode === "autoplay" && !isVimeo);
|
|
1251
|
+
const [isHovering, setIsHovering] = useState(false);
|
|
1252
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
1253
|
+
const [hasInitialized, setHasInitialized] = useState(false);
|
|
1254
|
+
const playPromiseRef = useRef(null);
|
|
1255
|
+
const handleVideoError = useCallback(() => {
|
|
1256
|
+
setIsPlaying(false);
|
|
1257
|
+
}, []);
|
|
1258
|
+
const handleVideoLoad = useCallback(() => {
|
|
1259
|
+
const video = videoRef.current;
|
|
1260
|
+
if (!video || hasInitialized || isVimeo) {
|
|
1261
|
+
return;
|
|
1262
|
+
}
|
|
1263
|
+
if (mode === "autoplay") {
|
|
1264
|
+
video.currentTime = 10;
|
|
1265
|
+
setHasInitialized(true);
|
|
1266
|
+
}
|
|
1267
|
+
}, [mode, hasInitialized, isVimeo]);
|
|
1268
|
+
useEffect(() => {
|
|
1269
|
+
const video = videoRef.current;
|
|
1270
|
+
if (!video || isVimeo) {
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
video.addEventListener("loadeddata", handleVideoLoad);
|
|
1274
|
+
video.addEventListener("error", handleVideoError);
|
|
1275
|
+
return () => {
|
|
1276
|
+
video.removeEventListener("loadeddata", handleVideoLoad);
|
|
1277
|
+
video.removeEventListener("error", handleVideoError);
|
|
1278
|
+
};
|
|
1279
|
+
}, [handleVideoLoad, handleVideoError, isVimeo]);
|
|
1280
|
+
useEffect(() => {
|
|
1281
|
+
const video = videoRef.current;
|
|
1282
|
+
if (!video || isVimeo) {
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
if (playPromiseRef.current) {
|
|
1286
|
+
playPromiseRef.current.catch(() => {
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
if (isModalOpen) {
|
|
1290
|
+
video.pause();
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
if (isPlaying && hasInitialized) {
|
|
1294
|
+
playPromiseRef.current = video.play().catch(() => {
|
|
1295
|
+
setIsPlaying(false);
|
|
1296
|
+
});
|
|
1297
|
+
} else {
|
|
1298
|
+
video.pause();
|
|
1299
|
+
}
|
|
1300
|
+
return () => {
|
|
1301
|
+
if (playPromiseRef.current) {
|
|
1302
|
+
playPromiseRef.current.catch(() => {
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
}, [isPlaying, isModalOpen, hasInitialized, isVimeo]);
|
|
1307
|
+
useEffect(() => {
|
|
1308
|
+
if (isVimeo && previewIframeRef.current && mode === "autoplay") {
|
|
1309
|
+
const iframe = previewIframeRef.current;
|
|
1310
|
+
if (isModalOpen) {
|
|
1311
|
+
iframe.contentWindow?.postMessage('{"method":"pause"}', "*");
|
|
1312
|
+
} else {
|
|
1313
|
+
iframe.contentWindow?.postMessage('{"method":"play"}', "*");
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
}, [isModalOpen, isVimeo, mode]);
|
|
1317
|
+
const handleMouseEnter = useCallback(() => {
|
|
1318
|
+
setIsHovering(true);
|
|
1319
|
+
}, []);
|
|
1320
|
+
const handleMouseLeave = useCallback(() => {
|
|
1321
|
+
setIsHovering(false);
|
|
1322
|
+
}, []);
|
|
1323
|
+
const handleModalOpenChange = useCallback((open) => {
|
|
1324
|
+
setIsModalOpen(open);
|
|
1325
|
+
}, []);
|
|
1326
|
+
const handleKeyDown = useCallback((event) => {
|
|
1327
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
1328
|
+
event.preventDefault();
|
|
1329
|
+
setIsModalOpen(true);
|
|
1330
|
+
}
|
|
1331
|
+
}, []);
|
|
1332
|
+
const getButtonOpacity = () => {
|
|
1333
|
+
return isHovering ? "opacity-100" : "opacity-0";
|
|
1334
|
+
};
|
|
1335
|
+
const renderPreviewContent = () => {
|
|
1336
|
+
if (isVimeo && vimeoId) {
|
|
1337
|
+
if (mode === "autoplay") {
|
|
1338
|
+
return /* @__PURE__ */ jsx("div", { className: "relative h-full w-full scale-[1.02] overflow-hidden transition-transform duration-300 group-hover:scale-[1.04]", children: /* @__PURE__ */ jsx(
|
|
1339
|
+
"iframe",
|
|
1340
|
+
{
|
|
1341
|
+
allow: "autoplay; fullscreen; picture-in-picture",
|
|
1342
|
+
className: "absolute inset-0 h-full w-full",
|
|
1343
|
+
frameBorder: "0",
|
|
1344
|
+
ref: previewIframeRef,
|
|
1345
|
+
src: `https://player.vimeo.com/video/${vimeoId}?autoplay=1&loop=1&muted=1&controls=0&background=1&quality=auto&transparent=0&api=1`,
|
|
1346
|
+
style: {
|
|
1347
|
+
pointerEvents: "none",
|
|
1348
|
+
width: "100vw",
|
|
1349
|
+
height: "56.25vw",
|
|
1350
|
+
// 16:9 aspect ratio
|
|
1351
|
+
minHeight: "100%",
|
|
1352
|
+
minWidth: "177.78vh",
|
|
1353
|
+
// 16:9 aspect ratio
|
|
1354
|
+
transform: "translate(-50%, -50%)",
|
|
1355
|
+
position: "absolute",
|
|
1356
|
+
top: "50%",
|
|
1357
|
+
left: "50%"
|
|
1358
|
+
},
|
|
1359
|
+
title: `${title} preview`
|
|
1360
|
+
}
|
|
1361
|
+
) });
|
|
1362
|
+
}
|
|
1363
|
+
if (vimeoThumbnail) {
|
|
1364
|
+
return /* @__PURE__ */ jsx(
|
|
1365
|
+
Image,
|
|
1366
|
+
{
|
|
1367
|
+
alt: alt || `${title} video thumbnail`,
|
|
1368
|
+
className: "h-full w-full",
|
|
1369
|
+
imageClassName: "scale-[1.02] object-cover transition-transform duration-300 group-hover:scale-[1.04]",
|
|
1370
|
+
src: vimeoThumbnail
|
|
1371
|
+
}
|
|
1372
|
+
);
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
if (!isVimeo && videoSources.length > 0) {
|
|
1376
|
+
return /* @__PURE__ */ jsx(
|
|
1377
|
+
Video,
|
|
1378
|
+
{
|
|
1379
|
+
className: "h-full w-full scale-[1.02] object-cover transition-transform duration-300 group-hover:scale-[1.04]",
|
|
1380
|
+
fallbackText: "Your browser does not support the video tag.",
|
|
1381
|
+
ref: videoRef,
|
|
1382
|
+
sources: videoSources,
|
|
1383
|
+
style: { display: "block" }
|
|
1384
|
+
}
|
|
1385
|
+
);
|
|
1386
|
+
}
|
|
1387
|
+
return /* @__PURE__ */ jsx("div", { className: "flex h-full w-full items-center justify-center bg-gray-200 text-gray-500", children: "No video available" });
|
|
1388
|
+
};
|
|
1389
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("group relative h-full w-full overflow-hidden", aspectRatio, className), children: [
|
|
1390
|
+
renderPreviewContent(),
|
|
1391
|
+
/* @__PURE__ */ jsx(
|
|
1392
|
+
VideoDialog,
|
|
1393
|
+
{
|
|
1394
|
+
isOpen: isModalOpen,
|
|
1395
|
+
isVimeo,
|
|
1396
|
+
onOpenChange: handleModalOpenChange,
|
|
1397
|
+
title,
|
|
1398
|
+
trigger: /* @__PURE__ */ jsx(
|
|
1399
|
+
"button",
|
|
1400
|
+
{
|
|
1401
|
+
"aria-label": `Watch full ${title.toLowerCase()}`,
|
|
1402
|
+
className: cn(
|
|
1403
|
+
"absolute inset-0 z-10 flex items-center justify-center",
|
|
1404
|
+
"bg-black/20 transition-opacity duration-300",
|
|
1405
|
+
getButtonOpacity()
|
|
1406
|
+
),
|
|
1407
|
+
onKeyDown: handleKeyDown,
|
|
1408
|
+
onMouseEnter: handleMouseEnter,
|
|
1409
|
+
onMouseLeave: handleMouseLeave,
|
|
1410
|
+
type: "button",
|
|
1411
|
+
children: /* @__PURE__ */ jsx(IconButton, { "aria-label": `Open ${title} in full screen`, icon: "maximize" })
|
|
1412
|
+
}
|
|
1413
|
+
),
|
|
1414
|
+
videoSources,
|
|
1415
|
+
vimeoId
|
|
1416
|
+
}
|
|
1417
|
+
),
|
|
1418
|
+
isPlaying && videoRef.current?.readyState === 0 && /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-0 flex items-center justify-center bg-black/10", children: /* @__PURE__ */ jsx(LoaderCircle, { className: "size-6 animate-spin" }) })
|
|
1419
|
+
] });
|
|
1420
|
+
};
|
|
1421
|
+
var VIDEO_MIME = {
|
|
1422
|
+
mp4: "video/mp4",
|
|
1423
|
+
webm: "video/webm",
|
|
1424
|
+
ogg: "video/ogg",
|
|
1425
|
+
mov: "video/quicktime"
|
|
1426
|
+
};
|
|
1427
|
+
var VIDEO_SRC_REGEX = /\.(mp4|webm|ogg|mov)$/i;
|
|
1428
|
+
function isVideoSrc(src) {
|
|
1429
|
+
if (!src) {
|
|
1430
|
+
return false;
|
|
1431
|
+
}
|
|
1432
|
+
return VIDEO_SRC_REGEX.test(src);
|
|
1433
|
+
}
|
|
1434
|
+
function VideoThumbnail({ src, className }) {
|
|
1435
|
+
const videoRef = useRef(null);
|
|
1436
|
+
const isVisibleRef = useRef(false);
|
|
1437
|
+
const [revealed, setRevealed] = useState(false);
|
|
1438
|
+
useEffect(() => {
|
|
1439
|
+
const video = videoRef.current;
|
|
1440
|
+
if (!video) {
|
|
1441
|
+
return;
|
|
1442
|
+
}
|
|
1443
|
+
const motionQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
1444
|
+
const tryPlay = () => {
|
|
1445
|
+
if (isVisibleRef.current && !motionQuery.matches) {
|
|
1446
|
+
video.play().catch(() => {
|
|
1447
|
+
});
|
|
1448
|
+
} else {
|
|
1449
|
+
video.pause();
|
|
1450
|
+
}
|
|
1451
|
+
};
|
|
1452
|
+
const observer = new IntersectionObserver(
|
|
1453
|
+
(entries) => {
|
|
1454
|
+
const entry = entries.at(0);
|
|
1455
|
+
isVisibleRef.current = entry?.isIntersecting ?? false;
|
|
1456
|
+
tryPlay();
|
|
1457
|
+
},
|
|
1458
|
+
{ threshold: 0.25 }
|
|
1459
|
+
);
|
|
1460
|
+
const handleCanPlay = () => setRevealed(true);
|
|
1461
|
+
video.addEventListener("canplay", handleCanPlay);
|
|
1462
|
+
motionQuery.addEventListener("change", tryPlay);
|
|
1463
|
+
observer.observe(video);
|
|
1464
|
+
if (video.readyState >= 3) {
|
|
1465
|
+
setRevealed(true);
|
|
1466
|
+
}
|
|
1467
|
+
return () => {
|
|
1468
|
+
observer.disconnect();
|
|
1469
|
+
motionQuery.removeEventListener("change", tryPlay);
|
|
1470
|
+
video.removeEventListener("canplay", handleCanPlay);
|
|
1471
|
+
};
|
|
1472
|
+
}, []);
|
|
1473
|
+
return /* @__PURE__ */ jsx(
|
|
1474
|
+
"video",
|
|
1475
|
+
{
|
|
1476
|
+
className: cn(
|
|
1477
|
+
"transition-opacity duration-400 ease-out",
|
|
1478
|
+
revealed ? "opacity-100" : "opacity-0",
|
|
1479
|
+
className
|
|
1480
|
+
),
|
|
1481
|
+
loop: true,
|
|
1482
|
+
muted: true,
|
|
1483
|
+
playsInline: true,
|
|
1484
|
+
ref: videoRef,
|
|
1485
|
+
children: /* @__PURE__ */ jsx(
|
|
1486
|
+
"source",
|
|
1487
|
+
{
|
|
1488
|
+
src,
|
|
1489
|
+
type: VIDEO_MIME[src.split(".").pop()?.toLowerCase() ?? ""] ?? "video/mp4"
|
|
1490
|
+
}
|
|
1491
|
+
)
|
|
1492
|
+
}
|
|
1493
|
+
);
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
export { Image, MediaLightbox, MediaLightboxZoomCursor, Video, VideoDialog, VideoManagerContext, VideoManagerProvider, VideoModal, VideoThumbnail, clearImageAnimationCache, isVideoSrc, useMediaLightbox, useMediaLightboxZoomCursor, useVideoManager };
|
|
1497
|
+
//# sourceMappingURL=index.js.map
|
|
1498
|
+
//# sourceMappingURL=index.js.map
|